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

maintain estree string literal shape when cloned #14039

Merged
merged 1 commit into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/babel-parser/src/parser/node.js
Expand Up @@ -79,12 +79,17 @@ export function cloneStringLiteral(node: any): any {
return clonePlaceholder(node);
}
const cloned = Object.create(NodePrototype);
cloned.type = "StringLiteral";
cloned.type = type;
cloned.start = start;
cloned.end = end;
cloned.loc = loc;
cloned.range = range;
cloned.extra = extra;
if (node.raw !== undefined) {
// estree set node.raw instead of node.extra
cloned.raw = node.raw;
} else {
cloned.extra = extra;
}
cloned.value = node.value;
return cloned;
}
Expand Down

This file was deleted.

@@ -0,0 +1,4 @@
{
"sourceType": "module",
"plugins": ["flow", "jsx", "estree"]
}
@@ -0,0 +1 @@
export { "foo" } from "module-a";
@@ -0,0 +1,42 @@
{
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"program": {
"type": "Program",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"specifiers": [
{
"type": "ExportSpecifier",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"local": {
"type": "Literal",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"value": "foo",
"raw": "\"foo\""
},
"exported": {
"type": "Literal",
"start":9,"end":14,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":14}},
"raw": "\"foo\"",
"value": "foo"
}
}
],
"source": {
"type": "Literal",
"start":22,"end":32,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":32}},
"value": "module-a",
"raw": "\"module-a\""
},
"declaration": null,
"exportKind": "value"
}
]
}
}