mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* transform discard binding * refactor extract functions to utils.ts * expand scope integrity check to all binding identifiers * update incomplete comment * update test output fixtures * remove forXStatement skip * add more test cases * feat: remove trailing void patterns on ignoreFunctionLength assumption * make node 6 happy * add more test cases * skip some exec tests for Node < 12 * update tsconfig.json * update test fixtures * fix: handle integration issues * run basic exec test on Node.js >= 16 * update test case * feat: pass syntaxType from plugin option * skip basic test for Node.js 6 * add more test cases * add new multiple-void test case * fix: disable named evaluation for parenthesized rhs * fix: handle using named evaluation * Revert "fix: disable named evaluation for parenthesized rhs" This reverts commit 93cf63768e3d68778ee73935a6c8de9c9bba2e2e. * prefix anonymous function with 0, * improve takeVoidPatternComments * use NodePath#splitExportDeclaration * update test fixtures * update test options * update test fixtures due to regenerator runtime changes * fix: remove VoidPattern from LVal * fix: improve destructuring transform detection Previously the isPattern check includes void pattern, which would result to an infinite recursion as the void pattern keeps being queued. * fix incorrect typings * update isAnonymousFunctionDefinition
66 lines
1.7 KiB
JavaScript
66 lines
1.7 KiB
JavaScript
/**
|
|
*
|
|
* @param {import("@babel/core").PluginAPI} api
|
|
* @returns {import("@babel/core").PluginObject}
|
|
*/
|
|
module.exports = function(api) {
|
|
const spliceIndexAndActionsList = [
|
|
[0, [{
|
|
type: 'leading',
|
|
value: 'injected 0'
|
|
}], undefined],
|
|
[0, [{
|
|
type: 'trailing',
|
|
value: 'injected 1'
|
|
}], undefined],
|
|
[0, [{
|
|
type: 'leading',
|
|
value: 'injected 0'
|
|
}, {
|
|
type: 'trailing',
|
|
value: 'injected 1'
|
|
}], undefined],
|
|
[1, [{
|
|
type: 'leading',
|
|
value: 'injected 1'
|
|
}, {
|
|
type: 'trailing',
|
|
value: 'injected 2'
|
|
}], [{
|
|
type: 'inner',
|
|
value: 'injected 0'
|
|
}]]
|
|
];
|
|
const { types: t } = api;
|
|
/**
|
|
* @type {import("@babel/core").PluginObject}
|
|
*/
|
|
const plugin = {
|
|
name: 'babel-plugin-proposal-discard-binding-test-array-pattern-inner-comments-injected-void-pattern-injected-preserve-comments-injected',
|
|
visitor: {
|
|
Program(path) {
|
|
path.traverse({
|
|
ArrayPattern(path) {
|
|
const [spliceIndex, actions, arrayPatternActions = []] = spliceIndexAndActionsList.shift();
|
|
const voidPattern = t.voidPattern();
|
|
actions.forEach(action => {
|
|
t.addComments(
|
|
voidPattern, action.type,
|
|
[{ type: "CommentBlock", value: action.value }]
|
|
);
|
|
});
|
|
arrayPatternActions.forEach(action => {
|
|
t.addComments(
|
|
path.node, action.type,
|
|
[{ type: "CommentBlock", value: action.value }]
|
|
);
|
|
});
|
|
path.node.elements.splice(spliceIndex, 0, voidPattern);
|
|
}
|
|
});
|
|
},
|
|
}
|
|
};
|
|
return plugin;
|
|
};
|