exports.default = function () { return { visitor: _babelTraverse.visitors.merge([{ ArrowFunctionExpression: function ArrowFunctionExpression(path) { var params = path.get("params"); for (var _iterator = params, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var param = _ref; if (param.isRestElement() || param.isAssignmentPattern()) { path.arrowFunctionToShadowed(); break; } } } }, destructuring.visitor, rest.visitor, def.visitor]) }; };
this.pluginPasses.forEach((pluginPasses, index) => { this.call("pre", pluginPasses); this.log.debug("Start transform traverse"); traverse(this.ast, traverse.visitors.merge(this.pluginVisitors[index], pluginPasses), this.scope); this.log.debug("End transform traverse"); this.call("post", pluginPasses); });
transform(): BabelFileResult { this.call("pre"); this.log.debug(`Start transform traverse`); traverse(this.ast, traverse.visitors.merge(this.pluginVisitors, this.pluginPasses), this.scope); this.log.debug(`End transform traverse`); this.call("post"); return this.generate(); }
maybeInherit(loc: string) { let inherits = this.take("inherits"); if (!inherits) return; inherits = OptionManager.normalisePlugin(inherits, loc, "inherits"); this.manipulateOptions = this.chain(inherits, "manipulateOptions"); this.post = this.chain(inherits, "post"); this.pre = this.chain(inherits, "pre"); this.visitor = traverse.visitors.merge([inherits.visitor, this.visitor]); }
export default function () { return { visitor: visitors.merge([{ ArrowFunctionExpression(path) { // default/rest visitors require access to `arguments` const params: Array<NodePath> = path.get("params"); for (const param of params) { if (param.isRestElement() || param.isAssignmentPattern()) { path.arrowFunctionToShadowed(); break; } } } }, destructuring.visitor, rest.visitor, def.visitor]) }; }
exports["default"] = function () { return { visitor: _babelTraverse.visitors.merge([{ ArrowFunctionExpression: function ArrowFunctionExpression(path) { // default/rest visitors require access to `arguments` var params = path.get("params"); for (var _i = 0; _i < params.length; _i++) { var param = params[_i]; if (param.isRestElement() || param.isAssignmentPattern()) { path.arrowFunctionToShadowed(); break; } } } }, destructuring.visitor, rest.visitor, def.visitor]) }; };
transform(): BabelFileResult { // In the "pass per preset" mode, we have grouped passes. // Otherwise, there is only one plain pluginPasses array. for (let i = 0; i < this.pluginPasses.length; i++) { const pluginPasses = this.pluginPasses[i]; this.call("pre", pluginPasses); this.log.debug("Start transform traverse"); // merge all plugin visitors into a single visitor let visitor = traverse.visitors.merge(this.pluginVisitors[i], pluginPasses, this.opts.wrapPluginVisitorMethod); traverse(this.ast, visitor, this.scope); this.log.debug("End transform traverse"); this.call("post", pluginPasses); } return this.generate(); }
constructor({name, macroBody, scope, location}) { location = location || ''; traverse( macroBody, traverse.visitors.merge([ collectMacros, { ThisExpression() { throw new Error("Can not use `this` in macro" + location); }, Identifier({node}) { if ("arguments" === node.name) { throw new Error("Can not use `arguments` in macro" + location); } } } ]), scope ); this.name = name; this.macroBody = macroBody; this.scope = scope; }
parent1 = path.parentPath, parent2 = parent1.parentPath ; if ( t.isLabeledStatement(parent1) && parent1.node.label.name === 'macro' || t.isLabeledStatement(parent2) && parent2.node.label.name === 'macro' ) { warning(`FunctionDeclaration converted to macro. Incompatible with native JS behaviour${getLocationMessage(node)}`); Macro.register(node.id.name, path, parent2.scope); path.remove(); } } }; export const collectMacros = traverse.visitors.merge([ collectMacros1, collectMacros2 ]); export const processMacros = { CallExpression(path, state) { "use strict"; const {node} = path; if (node[$processedByMacro]) { return; } _processMacro(path, state || false); node[$processedByMacro] = true; } }; /* @todo
replace(node, parent, scope, remaps); } if (t.isAssignmentExpression(node)) { let ids = t.getBindingIdentifiers(node); for (let name in ids) { replace(ids[name], parent, scope, remaps); } } scope.traverse(node, replaceVisitor, remaps); } let letReferenceBlockVisitor = traverse.visitors.merge([{ Function(path, state) { path.traverse(letReferenceFunctionVisitor, state); return path.skip(); } }, tdzVisitor]); let letReferenceFunctionVisitor = traverse.visitors.merge([{ ReferencedIdentifier(path, state) { let ref = state.letReferences[path.node.name]; // not a part of our scope if (!ref) return; // this scope has a variable with the same name so it couldn't belong // to our let scope let localBinding = path.scope.getBindingIdentifier(path.node.name); if (localBinding && localBinding !== ref) return;
}; var verifyConstructorVisitor = _babelTraverse.visitors.merge([noMethodVisitor, { Super: function Super(path) { if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) { throw path.buildCodeFrameError("'super.*' is not allowed before super()"); } }, CallExpression: { exit: function exit(path) { if (path.get("callee").isSuper()) { this.hasBareSuper = true; if (!this.isDerived) { throw path.buildCodeFrameError("super() is only allowed in a derived constructor"); } } } }, ThisExpression: function ThisExpression(path) { if (this.isDerived && !this.hasBareSuper) { if (!path.inShadow("this")) { throw path.buildCodeFrameError("'this' is not allowed before super()"); } } } }]); var findThisesVisitor = _babelTraverse.visitors.merge([noMethodVisitor, {
//there is no way to skip certain keys while traversing function traverseNoKeys(nodePath, visitor, state, skipKeys) { visitors.explode(visitor); return traverse.node(nodePath.node, visitor, nodePath.scope, state, nodePath, skipKeys); }