Ensure computed method names don't lose quotes (#419)
parent
105a164423
commit
2a0e7b575c
|
@ -1587,17 +1587,20 @@ function printStatementSequence(path, options, print) {
|
|||
}
|
||||
|
||||
function printPropertyKey(path, options, print) {
|
||||
var node = path.getNode().key;
|
||||
const node = path.getNode();
|
||||
const key = node.key;
|
||||
|
||||
if (
|
||||
(node.type === "StringLiteral" ||
|
||||
node.type === "Literal" && typeof node.value === "string") &&
|
||||
isIdentifierName(node.value) &&
|
||||
(key.type === "StringLiteral" ||
|
||||
key.type === "Literal" && typeof key.value === "string") &&
|
||||
isIdentifierName(key.value) &&
|
||||
!node.computed &&
|
||||
// There's a bug in the flow parser where it throws if there are
|
||||
// unquoted unicode literals as keys. Let's quote them for now.
|
||||
(options.parser !== "flow" || node.value.match(/[a-zA-Z0-9$_]/))
|
||||
(options.parser !== "flow" || key.value.match(/[a-zA-Z0-9$_]/))
|
||||
) {
|
||||
// 'a' -> a
|
||||
return node.value;
|
||||
return key.value;
|
||||
}
|
||||
return path.call(print, "key");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
exports[`test classes.js 1`] = `
|
||||
"class c {
|
||||
[\"i\"]() {}
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class c {
|
||||
[\"i\"]() {
|
||||
}
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test test.js 1`] = `
|
||||
"var ColorId = {
|
||||
RED: \'R\',
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class c {
|
||||
["i"]() {}
|
||||
}
|
Loading…
Reference in New Issue