Upgrade flow parser to 0.45 (#1447)

This fixes all the unicode issues and spacing between elements in array.

Fixes #1336
Fixes #1427
Fixes #770
master
Christopher Chedeau 2017-04-27 14:59:18 -07:00 committed by GitHub
parent e75d3a4af3
commit 3161bd0787
12 changed files with 134 additions and 47 deletions

View File

@ -15,7 +15,7 @@
"babylon": "7.0.0-beta.8",
"chalk": "1.1.3",
"esutils": "2.0.2",
"flow-parser": "0.43.0",
"flow-parser": "0.45.0",
"get-stdin": "5.0.1",
"glob": "7.1.1",
"jest-validate": "19.0.0",

View File

@ -2180,10 +2180,7 @@ function printPropertyKey(path, options, print) {
(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" || key.value.match(/[a-zA-Z0-9$_]/))
!node.computed
) {
// 'a' -> a
return path.call(
@ -3412,13 +3409,6 @@ function nodeStr(node, options) {
const str = node.value;
isString.assert(str);
// Workaround a bug in the Javascript version of the flow parser where
// astral unicode characters like \uD801\uDC28 are incorrectly parsed as
// a sequence of \uFFFD.
if (options.parser === "flow" && str.indexOf("\ufffd") !== -1) {
return node.raw;
}
const raw = node.extra ? node.extra.raw : node.raw;
// `rawContent` is the string exactly like it appeared in the input source
// code, with its enclosing quote.

View File

@ -341,6 +341,7 @@ Foo.bar();
var FooLegacy = React.createClass({
is_mounted: (undefined: ?boolean),
propTypes: {
x: React.PropTypes.number.isRequired
},

View File

@ -2220,6 +2220,7 @@ function foo(text: string | number): string {
return "wat";
}
}
function bar(text: string | number): string {
switch (typeof text) {
case "string":
@ -2228,16 +2229,17 @@ function bar(text: string | number): string {
return text++ + "";
}
}
function baz1(text: string | number): string {
switch (typeof text) {
case "number":
case "string":
return text[0];
// error, [0] on number
return text[0]; // error, [0] on number
default:
return "wat";
}
}
function baz2(text: string | number): string {
switch (typeof text) {
case "string":
@ -2247,12 +2249,15 @@ function baz2(text: string | number): string {
return "wat";
}
}
function corge(text: string | number | Array<string>): string {
switch (typeof text) {
case "object":
return text[0];
case "string":
case "number": // using ++ since it isn't valid on arrays or strings. // should only error for string since Array was filtered out.
case "number":
// using ++ since it isn't valid on arrays or strings.
// should only error for string since Array was filtered out.
return text++ + "";
default:
return "wat";

View File

@ -320,3 +320,46 @@ exports[`quotes.js 1`] = `
<div id={"'\\"&quot;<>&amp;quot;"} />;
`;
exports[`spacing.js 1`] = `
const Labels = {
label1: (
<fbt>
Label 1
</fbt>
),
label2: (
<fbt>
Label 2
</fbt>
),
label3: (
<fbt>
Label 3
</fbt>
),
};
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const Labels = {
label1: (
<fbt>
Label 1
</fbt>
),
label2: (
<fbt>
Label 2
</fbt>
),
label3: (
<fbt>
Label 3
</fbt>
)
};
`;

19
tests/jsx/spacing.js Normal file
View File

@ -0,0 +1,19 @@
const Labels = {
label1: (
<fbt>
Label 1
</fbt>
),
label2: (
<fbt>
Label 2
</fbt>
),
label3: (
<fbt>
Label 3
</fbt>
),
};

View File

@ -26,6 +26,7 @@ raw_amp = <span>foo & bar</span>
many_nbsp = <div>&nbsp; &nbsp; </div>;
single_nbsp = <div>&nbsp;</div>;
many_raw_nbsp = <div>&nbsp;&nbsp;&nbsp;</div>;
amp = <span>foo &amp; bar</span>;
raw_amp = <span>foo & bar</span>;

View File

@ -305,6 +305,7 @@ class A {
// none of the semicolons above this comment can be omitted.
// none of the semicolons below this comment are necessary.
q() {}
[h]() {}
@ -632,6 +633,7 @@ class A {
// none of the semicolons above this comment can be omitted.
// none of the semicolons below this comment are necessary.
q() {}
[h]() {}

View File

@ -117,31 +117,44 @@ exports[`strings.js 1`] = `
"\\0";
// Emoji.
"🐶"; // Empty string.
"🐶";
// Empty string.
"";
""; // Single double quote.
"";
// Single double quote.
'"';
'"'; // Single single quote.
'"';
// Single single quote.
"'";
"'"; // Unnecessary escapes.
"'";
'"'; // One of each.
// Unnecessary escapes.
"'";
'"';
// One of each.
"\\"'";
"\\"'"; // One of each with unnecessary escapes.
"\\"'";
"\\"'"; // More double quotes than single quotes.
// One of each with unnecessary escapes.
"\\"'";
"\\"'";
// More double quotes than single quotes.
'"\\'"';
'"\\'"'; // More single quotes than double quotes.
'"\\'"';
// More single quotes than double quotes.
"\\"''";
"\\"''"; // Two of each.
"\\"''";
// Two of each.
"\\"\\"''";
"\\"\\"''"; // Single backslash.
"\\"\\"''";
// Single backslash.
"\\\\";
"\\\\"; // Backslases.
"\\\\";
// Backslases.
"\\"\\\\\\"\\\\\\\\\\" ''\\\\'\\\\'\\\\\\\\'";
'\\'\\\\\\'\\\\\\\\\\' ""\\\\"\\\\"\\\\\\\\"'; // Somewhat more real-word example.
'\\'\\\\\\'\\\\\\\\\\' ""\\\\"\\\\"\\\\\\\\"';
// Somewhat more real-word example.
"He's sayin': \\"How's it goin'?\\" Don't ask me why.";
"He's sayin': \\"How's it goin'?\\" Don't ask me why."; // Somewhat more real-word example 2.
"He's sayin': \\"How's it goin'?\\" Don't ask me why.";
// Somewhat more real-word example 2.
'var backslash = "\\\\", doubleQuote = \\'"\\';';
'var backslash = "\\\\", doubleQuote = \\'"\\';';
@ -234,31 +247,44 @@ exports[`strings.js 2`] = `
'\\0';
// Emoji.
'🐶'; // Empty string.
'🐶';
// Empty string.
'';
''; // Single double quote.
'';
// Single double quote.
'"';
'"'; // Single single quote.
'"';
// Single single quote.
"'";
"'"; // Unnecessary escapes.
"'";
'"'; // One of each.
// Unnecessary escapes.
"'";
'"';
// One of each.
'"\\'';
'"\\''; // One of each with unnecessary escapes.
'"\\'';
'"\\''; // More double quotes than single quotes.
// One of each with unnecessary escapes.
'"\\'';
'"\\'';
// More double quotes than single quotes.
'"\\'"';
'"\\'"'; // More single quotes than double quotes.
'"\\'"';
// More single quotes than double quotes.
"\\"''";
"\\"''"; // Two of each.
"\\"''";
// Two of each.
'""\\'\\'';
'""\\'\\''; // Single backslash.
'""\\'\\'';
// Single backslash.
'\\\\';
'\\\\'; // Backslases.
'\\\\';
// Backslases.
"\\"\\\\\\"\\\\\\\\\\" ''\\\\'\\\\'\\\\\\\\'";
'\\'\\\\\\'\\\\\\\\\\' ""\\\\"\\\\"\\\\\\\\"'; // Somewhat more real-word example.
'\\'\\\\\\'\\\\\\\\\\' ""\\\\"\\\\"\\\\\\\\"';
// Somewhat more real-word example.
"He's sayin': \\"How's it goin'?\\" Don't ask me why.";
"He's sayin': \\"How's it goin'?\\" Don't ask me why."; // Somewhat more real-word example 2.
"He's sayin': \\"How's it goin'?\\" Don't ask me why.";
// Somewhat more real-word example 2.
'var backslash = "\\\\", doubleQuote = \\'"\\';';
'var backslash = "\\\\", doubleQuote = \\'"\\';';

View File

@ -49,7 +49,7 @@ exports[`strings.js 1`] = `
"\\0",
"🐶",
'\\uD801\\uDC28'
"\\uD801\\uDC28"
];
`;
@ -103,7 +103,7 @@ exports[`strings.js 2`] = `
"\\0",
"🐶",
'\\uD801\\uDC28',
"\\uD801\\uDC28",
];
`;

View File

@ -3,6 +3,6 @@
exports[`keys.js 1`] = `
({'この事はつもり素晴らしいことさ': '35jL9V'})
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
({ "この事はつもり素晴らしいことさ": "35jL9V" });
({ この事はつもり素晴らしいことさ: "35jL9V" });
`;

View File

@ -746,9 +746,9 @@ find-up@^2.1.0:
dependencies:
locate-path "^2.0.0"
flow-parser@0.43.0:
version "0.43.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.43.0.tgz#e2b8eb1ac83dd53f7b6b04a7c35b6a52c33479b7"
flow-parser@0.45.0:
version "0.45.0"
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.45.0.tgz#aa29d4ae27f06aa02817772bba0fcbefef7e62f0"
for-in@^0.1.5:
version "0.1.6"