ascjs
ascjs copied to clipboard
Error when transforming export * from relative module path.
rimraf cjs/* && ascjs esm cjs
/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:137
}${specifier.local.name}${EOL}`;
^
TypeError: Cannot read property 'name' of undefined
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:137:26
at Array.forEach (<anonymous>)
at Object.ExportNamedDeclaration (/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:132:21)
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:171:37
at Array.forEach (<anonymous>)
at parse (/Users/bret/littlstar/sdk-js/node_modules/ascjs/index.js:169:23)
at ascjs (/Users/bret/littlstar/sdk-js/node_modules/ascjs/bin.js:6:18)
at /Users/bret/littlstar/sdk-js/node_modules/ascjs/bin.js:99:25
It throws when I try to transform this file:
export * as commands from './commands/index.js'
Reverting to 4.0.2 (and lower) and the transform continues to work. Not a show stopper on my end, work arounds aplenty.
Digging into what change might have caused this, and what that change changed.
Putting together a reproducible test case.
does ucjs fail too?
Oh I had no idea about that package. Is that the newer version of this tool? I can test it out
rather than newer, it's different, as it uses mostly Babel without much AST traversing ... curious to know if it has the same issue, as estree was breking in one of my recent projects, so I'd like not to put it back, and offer that alternative in the README in case of issues.
Doesn't seem to work on that file:
rimraf cjs/* && ucjs esm/cli cjs
Warning: unable to parse /Users/bret/littlstar/sdk-js/esm/cli/index.js code
SyntaxError: unknown: Unexpected export specifier type
> 1 | export * as commands from './commands/index.js'
| ^^^^^^^^^^^^^
2 |
at File.buildCodeFrameError (/Users/bret/littlstar/sdk-js/node_modules/@babel/core/lib/transformation/file/file.js:250:12)
at NodePath.buildCodeFrameError (/Users/bret/littlstar/sdk-js/node_modules/@babel/traverse/lib/path/index.js:138:21)
at /Users/bret/littlstar/sdk-js/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js:170:22
at Array.forEach (<anonymous>)
at /Users/bret/littlstar/sdk-js/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js:168:31
at Array.forEach (<anonymous>)
at getModuleMetadata (/Users/bret/littlstar/sdk-js/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js:116:27)
at normalizeModuleAndLoadMetadata (/Users/bret/littlstar/sdk-js/node_modules/@babel/helper-module-transforms/lib/normalize-and-load-metadata.js:42:7)
at rewriteModuleStatementsAndPrepareHeader (/Users/bret/littlstar/sdk-js/node_modules/@babel/helper-module-transforms/lib/index.js:77:54)
at PluginPass.exit (/Users/bret/littlstar/sdk-js/node_modules/@babel/plugin-transform-modules-commonjs/lib/index.js:145:83) {
code: 'BABEL_TRANSFORM_ERROR'
}
Maybe its a matter of turning on a plugin or set more options on the @babel/plugin-transform-modules-commonjs plugin in ucjs? All solutions I dig up just say turn on env, but thats not what this tool is for.
env is heavy ... and I wonder if I'm missing some ImportAll AST traversing call in here ... will have a look soon, but not too soon as I'm quite busy these days, but if you find a solution, feel free to update the PR (and in case please squash all commits so it's easier to see its latest, most updated, state), thanks.
Seeing some evidence that maybe export * as was some kind of edge case in the spec, that babel supported, but wasn't officially spec compliant. Not 100% sure on that.
Source:
https://2ality.com/2014/09/es6-modules-final.html
where someone in the comments asks
Why is
export * as foo from "./foo"not supported? It currently works with babel. But I'm surprised it really not mentioned in spec...
🤔
will have a look soon, but not too soon as I'm quite busy these days,
No problem! Just opening issues as I run into them and will provide any solutions I come across. Thank you for all your time the last few days.
heh, it wasn't much time ... 'cause I don't have much of it these days 😅
next week I'll be on vacation and I'll find some time to dig into this issue as I use ascjs almost everywhere
Ok export * as is supported in ecma-262, but apparently not in (some) lower versions of the spec.
http://www.ecma-international.org/ecma-262/11.0/index.html#title
Guessing its a matter of some esoteric babel config.
Rewriting as, without the newer syntax:
import * as commands from './commands/index.js'
export {
commands
}
works just as well. Have lots of other stuff to do as well, so I'll settle for this until I have more time to dig in.
Tried adding
'@babel/plugin-proposal-export-namespace-from',
'@babel/plugin-proposal-export-default-from',
To no avail.