Question: whats the policy about having “correct” node types at correct positions? but expression is allowed there, other code might totally not expect it being there but if we had parse the output it would be ofc a declaration and not an expression i.e. its possible to transform arrow function to expression in export default declaration position

Asked By
andarist
Asked At
2018-02-11 23:22:50

Found 15 possible answers.

User Answered At Possible Answer
loganfsmyth 2018-02-11 23:24:32 that example seems off to me since arrows are expressions?
andarist 2018-02-11 23:25:40 export default () => {} with transform-arrow-functions
loganfsmyth 2018-02-11 23:26:00 oh as in convert to a function expression?
andarist 2018-02-11 23:26:06 yeah
loganfsmyth 2018-02-11 23:26:21 in this case it's fine because it'll still serialize as a function expression
with parens
export default (function(){});
andarist 2018-02-11 23:28:44 hm, ok - need to re-check 2morrow what caused the issue for me then i might have converted this to declaration prematurely
loganfsmyth 2018-02-11 23:31:17 sounds good
andarist 2018-02-11 23:32:38 wouldnt be able to sleep :sweat_smile: so ive checked it now is there some method like path.canBeScopeBoundary ? lolz, ive registered a binding on that tricky expression instead of on its parent this makes reasoning about transforms even harder :wink: somewhere along the transformations ive lost the associated binding :< because i havent named this tricky expression i didnt take into an account such situation, didnt know that such expression might pop up at export declaration position
loganfsmyth 2018-02-11 23:40:52 .isScope I think? scopes are hard though
andarist 2018-02-11 23:41:57 yeah, i see that - would be great to have them auto-synced like in all cases :wink:
loganfsmyth 2018-02-11 23:42:33 agreed
andarist 2018-02-11 23:42:41 there is also isScopeable , do u know the difference?
loganfsmyth 2018-02-11 23:42:48 really I wish they didn't exist at all, but making that fast would be real tough
andarist 2018-02-11 23:44:13 yeah, agreed
loganfsmyth 2018-02-11 23:45:52 Scopeable is the alias: https://github.com/babel/babel/blob/master/packages/babel-types/src/definitions/core.js#L106 , and isScope checks those using https://github.com/babel/babel/blob/master/packages/babel-types/src/validators/isScope.js#L12 the chaining between NodePath and babel-types is hard to follow :disappointed: indirectly via https://github.com/babel/babel/blob/master/packages/babel-traverse/src/path/lib/virtual-types.js#L63

Related Questions