Skip to content

Commit c284d63

Browse files
wip(core): vue2 support, fix "not a params of a function" in shouldPrependVm() (+ misc comments)
1 parent 7349e72 commit c284d63

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

build/fakeBuble.mjs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function transform(source, opts) {
2626
// babel types: https://babeljs.io/docs/en/babel-types
2727
// doc: https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-inserting-a-sibling-node
2828
// astexplorer: https://astexplorer.net/
29-
// buble/src/program/types/WithStatement.js : https://github.com/yyx990803/buble/blob/f5996c9cdb2e61cb7dddf0f6c6f25d0f3f600055/src/program/types/WithStatement.js
3029

3130
const srcAst = parse(source);
3231

@@ -42,10 +41,26 @@ export function transform(source, opts) {
4241
hash[name] = true
4342
})
4443

45-
const isDeclaration = type => /Declaration$/.test(type);
46-
const isFunction = type => /Function(Expression|Declaration)$/.test(type);
4744

48-
// see https://github.com/yyx990803/buble/blob/f5996c9cdb2e61cb7dddf0f6c6f25d0f3f600055/src/utils/prependVm.js#L6
45+
// all buble types : https://github.com/yyx990803/buble/blob/f5996c9cdb2e61cb7dddf0f6c6f25d0f3f600055/src/program/types/index.js
46+
47+
// ClassDeclaration,
48+
// ExportNamedDeclaration,
49+
// ExportDefaultDeclaration,
50+
// FunctionDeclaration,
51+
// ImportDeclaration,
52+
// VariableDeclaration,
53+
54+
const isDeclaration = type => /Declaration$/.test(type); // match babel types
55+
56+
57+
// ArrowFunctionExpression,
58+
// FunctionDeclaration,
59+
// FunctionExpression,
60+
61+
const isFunction = type => /Function(Expression|Declaration)$/.test(type); // match babel types
62+
63+
// see yyx990803/buble prependVm.js : https://github.com/yyx990803/buble/blob/master/src/utils/prependVm.js
4964
function shouldPrependVm(identifier) {
5065

5166
if (
@@ -54,7 +69,7 @@ export function transform(source, opts) {
5469
!(isDeclaration(identifier.parent.type) && identifier.parent.id === identifier) &&
5570

5671
// not a params of a function
57-
!(isFunction(identifier.parent.type) && identifier.parent.params.indexOf(identifier) > -1) &&
72+
!(isFunction(identifier.parent.type) && identifier.parent.params.indexOf(identifier.node) > -1) &&
5873

5974
// not a key of Property
6075
!(identifier.parent.type === 'ObjectProperty' && identifier.parent.key === identifier.node && !identifier.parent.computed) &&
@@ -97,7 +112,9 @@ export function transform(source, opts) {
97112

98113
traverse(srcAst, {
99114

100-
// https://babeljs.io/docs/en/babel-types#withstatement
115+
// babel withstatement https://babeljs.io/docs/en/babel-types#withstatement
116+
// see yyx990803/buble WithStatement.js : https://github.com/yyx990803/buble/blob/master/src/program/types/WithStatement.js
117+
101118
WithStatement(path) {
102119

103120
path.traverse(withStatementVisitor);

0 commit comments

Comments
 (0)