Skip to content

Commit

Permalink
maintain estree string literal shape when cloned (#14039)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Dec 9, 2021
1 parent 94af0e5 commit 3908049
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
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"
}
]
}
}

0 comments on commit 3908049

Please sign in to comment.