Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: traveler[child.type] is not a function #39

Open
morganney opened this issue Jun 26, 2023 · 0 comments · May be fixed by #40
Open

TypeError: traveler[child.type] is not a function #39

morganney opened this issue Jun 26, 2023 · 0 comments · May be fixed by #40

Comments

@morganney
Copy link

morganney commented Jun 26, 2023

Example code to reproduce the issue:

const comments = []
const source = [
  "Promise.all([import('foo')])",
  '// Some comment'
].join('\n')
const ast = acorn.parse(source, {
  onComment: comments,
  sourceType: 'module',
  locations: true,
  ecmaVersion: 2023
})
astravel.attachComments(ast, comments)

You can see a demo on the astring demo site (be sure to check the Include comments checkbox). It produces the following stack trace:

TypeError: traveler2[child.type] is not a function

TypeError: traveler2[child.type] is not a function
    at attachCommentsToNode (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:456:26)
    at Object.ArrayExpression (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:481:5)
    at Object.go (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:12:22)
    at Object.CallExpression (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:271:12)
    at Object.go (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:12:22)
    at Object.ExpressionStatement (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:58:10)
    at attachCommentsToNode (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:456:26)
    at Object.Block$1 (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:471:3)
    at Module.attachComments (https://cdn.skypack.dev/-/[email protected]/dist=es2019,mode=imports/optimized/astravel.js:491:22)
    at HTMLTextAreaElement.update (https://david.bonnet.cc/astring/demo/:78:22)

Seems to be specific to a Promise.all expression that includes an ImportExpression, e.g., Promise.all([import('foo')]). Any comment type following that will produce the error.

EDIT: The error can be triggered with this simplified source

[import('foo')]
// Some comment

Potentially related to davidbonnet/astring#562.

@morganney morganney linked a pull request Jun 28, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant