@@ -26,7 +26,6 @@ export function transform(source, opts) {
26
26
// babel types: https://babeljs.io/docs/en/babel-types
27
27
// doc: https://github.com/jamiebuilds/babel-handbook/blob/master/translations/en/plugin-handbook.md#toc-inserting-a-sibling-node
28
28
// astexplorer: https://astexplorer.net/
29
- // buble/src/program/types/WithStatement.js : https://github.com/yyx990803/buble/blob/f5996c9cdb2e61cb7dddf0f6c6f25d0f3f600055/src/program/types/WithStatement.js
30
29
31
30
const srcAst = parse ( source ) ;
32
31
@@ -42,10 +41,26 @@ export function transform(source, opts) {
42
41
hash [ name ] = true
43
42
} )
44
43
45
- const isDeclaration = type => / D e c l a r a t i o n $ / . test ( type ) ;
46
- const isFunction = type => / F u n c t i o n ( E x p r e s s i o n | D e c l a r a t i o n ) $ / . test ( type ) ;
47
44
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 => / D e c l a r a t i o n $ / . test ( type ) ; // match babel types
55
+
56
+
57
+ // ArrowFunctionExpression,
58
+ // FunctionDeclaration,
59
+ // FunctionExpression,
60
+
61
+ const isFunction = type => / F u n c t i o n ( E x p r e s s i o n | D e c l a r a t i o n ) $ / . test ( type ) ; // match babel types
62
+
63
+ // see yyx990803/buble prependVm.js : https://github.com/yyx990803/buble/blob/master/src/utils/prependVm.js
49
64
function shouldPrependVm ( identifier ) {
50
65
51
66
if (
@@ -54,7 +69,7 @@ export function transform(source, opts) {
54
69
! ( isDeclaration ( identifier . parent . type ) && identifier . parent . id === identifier ) &&
55
70
56
71
// 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 ) &&
58
73
59
74
// not a key of Property
60
75
! ( identifier . parent . type === 'ObjectProperty' && identifier . parent . key === identifier . node && ! identifier . parent . computed ) &&
@@ -97,7 +112,9 @@ export function transform(source, opts) {
97
112
98
113
traverse ( srcAst , {
99
114
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
+
101
118
WithStatement ( path ) {
102
119
103
120
path . traverse ( withStatementVisitor ) ;
0 commit comments