Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exit(path, state) {
// We must traverse the AST again because the third party
// transform-es2015-modules-amd emits its define() call after
// Program exit :-(
firstDefineNamespaced = false;
extraNamespaceCount = 0;
path.traverse(namespaceVisitor, {opts: state.opts});
if (extraNamespaceCount > 0) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
if (firstDefineNamespaced) {
log.info(
'namespace-amd-define',
'Namespaced first AMD define in file'
);
}
if (extraNamespaceCount) {
log.warn(
'namespace-amd-define',
'Found',
extraNamespaceCount,
'define() calls inside the module definition',
exit(path, state) {
// We must traverse the AST again because the
// transform-es2015-modules-amd plugin emits its define()
// call after exiting Program node :-(
path.traverse(amdDefineVisitor, state);
// Dump final report statistics
if (
state.namesCount > 0 ||
state.depsCount > 0 ||
state.requiresCount > 0
) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
log.info(
'namespace-modules',
'Namespaced',
state.namesCount,
'define() names,',
state.depsCount,
'define() dependencies,',
'and',
state.requiresCount,
'require() names'
);
}
},
exit(path, state) {
if (state.normalizeCount) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
log.info(
'normalize-requires',
'Normalized',
state.normalizeCount,
'requires'
);
}
},
},
enter(path, state) {
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
state.log = log;
},
exit(path, state) {
if (state.esModuleFlagAdded) {
return;
}
const {filename} = state.file.opts;
const pkgDir = babelUtil.getPackageDir(filename);
const pkgJson = readJsonSync(npath.join(pkgDir, 'package.json'));
const {rootPkgJson} = babelIpc.get(state);
const pkgId =
pkgJson.name === rootPkgJson.name
? '/'
: `${pkgJson.name}@${pkgJson.version}`;
const {manifest} = babelIpc.get(state);
manifest.addModuleFlags(pkgId, npath.relative(pkgDir, filename), {
esModule: true,
});
state.esModuleFlagAdded = true;
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
log.info('add-module-metadata', "Added 'esModule' flag");
}
const {rootPkgJson} = babelIpc.get(state);
const pkgId =
pkgJson.name === rootPkgJson.name
? '/'
: `${pkgJson.name}@${pkgJson.version}`;
const {manifest} = babelIpc.get(state);
manifest.addModuleFlags(pkgId, npath.relative(pkgDir, filename), {
esModule: true,
});
state.esModuleFlagAdded = true;
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
log.info('add-module-metadata', "Added 'esModule' flag");
}
Identifier(path, state) {
const {node} = path;
const {dependencies} = state;
const {log} = babelIpc.get(state, () => ({
log: new PluginLogger(),
}));
if (node.name === 'require') {
const parent = path.parent;
if (
path.scope.hasBinding('require') &&
!state['webpackWarnIssued']
) {
state['webpackWarnIssued'] = true;
log.warn(
'wrap-modules-amd',
`Module looks like a webpack bundle, local require() ` +
`calls will be ignored`
constructor(state) {
const babelIpcObject: BabelIpcObject = babelIpc.get(state, {});
this._aliasFields = getAliasFields(
babelIpcObject.globalConfig,
state.opts
);
this._absFile = new FilePath(state.file.opts.filename);
this._log = babelIpcObject.log;
this._absRootDir = new FilePath(
this._absFile.asNative.startsWith(absBuildDirPath)
? absBuildDirPath
: absPrjDirPath
);
state.visitor = this;
}