astring
astring copied to clipboard
Does not handle literal module specifier
Motivation
Hi, thanks for the work!
It seems astring
does not handle module specifier when they are literals and not identifiers.
import { parse } from "acorn";
import { generate } from "astring";
const root = parse("export { 'foo-bar' as 'qux-baz' } from 'source';", {
sourceType: "module",
ecmaVersion: 2024,
});
console.dir(root, { depth: 1 / 0 });
console.log(generate(root));
Node {
type: 'Program',
start: 0,
end: 48,
body: [
Node {
type: 'ExportNamedDeclaration',
start: 0,
end: 48,
declaration: null,
specifiers: [
Node {
type: 'ExportSpecifier',
start: 9,
end: 31,
local: Node {
type: 'Literal',
start: 9,
end: 18,
value: 'foo-bar',
raw: "'foo-bar'"
},
exported: Node {
type: 'Literal',
start: 22,
end: 31,
value: 'qux-baz',
raw: "'qux-baz'"
}
}
],
source: Node {
type: 'Literal',
start: 39,
end: 47,
value: 'source',
raw: "'source'"
}
}
],
sourceType: 'module'
}
export {undefined} from 'source';
Expected behavior
export { 'foo-bar' as 'qux-baz' } from 'source';
Actual behavior
export {undefined} from 'source';