Skip to content

Commit e3a845a

Browse files
committed
Merge pull request #5641 from RyanCavanaugh/fix5634
Quote only names that need to be quoted, not the reverse
2 parents 63ff012 + f90ef92 commit e3a845a

File tree

7 files changed

+113
-8
lines changed

7 files changed

+113
-8
lines changed

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,13 +1592,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
15921592
/// these emit into an object literal property name, we don't need to be worried
15931593
/// about keywords, just non-identifier characters
15941594
function emitAttributeName(name: Identifier) {
1595-
if (/[A-Za-z_]+[\w*]/.test(name.text)) {
1596-
write("\"");
1595+
if (/^[A-Za-z_]\w*$/.test(name.text)) {
15971596
emit(name);
1598-
write("\"");
15991597
}
16001598
else {
1599+
write("\"");
16011600
emit(name);
1601+
write("\"");
16021602
}
16031603
}
16041604

tests/baselines/reference/getEmitOutputTsxFile_React.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ declare class Bar {
1717

1818
EmitSkipped: false
1919
FileName : tests/cases/fourslash/inputFile2.js.map
20-
{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,KAAC,IAAI,GAAG,CAAE,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.js
20+
{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,qBAAC,GAAG,IAAC,IAAI,EAAG,CAAE,EAAG,CAAA"}FileName : tests/cases/fourslash/inputFile2.js
2121
var y = "my div";
22-
var x = React.createElement("div", {"name": y});
22+
var x = React.createElement("div", {name: y});
2323
//# sourceMappingURL=inputFile2.js.mapFileName : tests/cases/fourslash/inputFile2.d.ts
2424
declare var y: string;
2525
declare var x: any;

tests/baselines/reference/keywordInJsxIdentifier.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ declare var React: any;
99

1010
//// [keywordInJsxIdentifier.js]
1111
React.createElement("foo", {"class-id": true});
12-
React.createElement("foo", {"class": true});
12+
React.createElement("foo", {class: true});
1313
React.createElement("foo", {"class-id": "1"});
14-
React.createElement("foo", {"class": "1"});
14+
React.createElement("foo", {class: "1"});

tests/baselines/reference/tsxExternalModuleEmit2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ declare var Foo, React;
2020
//// [app.js]
2121
var mod_1 = require('mod');
2222
// Should see mod_1['default'] in emit here
23-
React.createElement(Foo, {"handler": mod_1["default"]});
23+
React.createElement(Foo, {handler: mod_1["default"]});
2424
// Should see mod_1['default'] in emit here
2525
React.createElement(Foo, React.__spread({}, mod_1["default"]));
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(9,10): error TS2304: Cannot find name 'React'.
2+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(10,10): error TS2304: Cannot find name 'React'.
3+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(11,10): error TS2304: Cannot find name 'React'.
4+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(12,10): error TS2304: Cannot find name 'React'.
5+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(15,10): error TS2304: Cannot find name 'React'.
6+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(16,10): error TS2304: Cannot find name 'React'.
7+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(17,10): error TS2304: Cannot find name 'React'.
8+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(18,10): error TS2304: Cannot find name 'React'.
9+
tests/cases/conformance/jsx/tsxReactEmit7.tsx(19,10): error TS2304: Cannot find name 'React'.
10+
11+
12+
==== tests/cases/conformance/jsx/tsxReactEmit7.tsx (9 errors) ====
13+
14+
declare module JSX {
15+
interface Element { }
16+
interface IntrinsicElements {
17+
[s: string]: any;
18+
}
19+
}
20+
21+
var m = <div x-y="val"></div>;
22+
~~~
23+
!!! error TS2304: Cannot find name 'React'.
24+
var n = <div xx-y="val"></div>;
25+
~~~
26+
!!! error TS2304: Cannot find name 'React'.
27+
var o = <div x-yy="val"></div>;
28+
~~~
29+
!!! error TS2304: Cannot find name 'React'.
30+
var p = <div xx-yy="val"></div>;
31+
~~~
32+
!!! error TS2304: Cannot find name 'React'.
33+
34+
// Investigation
35+
var a = <div x="val"></div>;
36+
~~~
37+
!!! error TS2304: Cannot find name 'React'.
38+
var b = <div xx="val"></div>;
39+
~~~
40+
!!! error TS2304: Cannot find name 'React'.
41+
var c = <div xxx="val"></div>;
42+
~~~
43+
!!! error TS2304: Cannot find name 'React'.
44+
var d = <div xxxx="val"></div>;
45+
~~~
46+
!!! error TS2304: Cannot find name 'React'.
47+
var e = <div xxxxx="val"></div>;
48+
~~~
49+
!!! error TS2304: Cannot find name 'React'.
50+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tsxReactEmit7.tsx]
2+
3+
declare module JSX {
4+
interface Element { }
5+
interface IntrinsicElements {
6+
[s: string]: any;
7+
}
8+
}
9+
10+
var m = <div x-y="val"></div>;
11+
var n = <div xx-y="val"></div>;
12+
var o = <div x-yy="val"></div>;
13+
var p = <div xx-yy="val"></div>;
14+
15+
// Investigation
16+
var a = <div x="val"></div>;
17+
var b = <div xx="val"></div>;
18+
var c = <div xxx="val"></div>;
19+
var d = <div xxxx="val"></div>;
20+
var e = <div xxxxx="val"></div>;
21+
22+
23+
//// [tsxReactEmit7.js]
24+
var m = React.createElement("div", {"x-y": "val"});
25+
var n = React.createElement("div", {"xx-y": "val"});
26+
var o = React.createElement("div", {"x-yy": "val"});
27+
var p = React.createElement("div", {"xx-yy": "val"});
28+
// Investigation
29+
var a = React.createElement("div", {x: "val"});
30+
var b = React.createElement("div", {xx: "val"});
31+
var c = React.createElement("div", {xxx: "val"});
32+
var d = React.createElement("div", {xxxx: "val"});
33+
var e = React.createElement("div", {xxxxx: "val"});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@jsx: react
2+
//@module: commonjs
3+
4+
//@filename: file.tsx
5+
declare module JSX {
6+
interface Element { }
7+
interface IntrinsicElements {
8+
[s: string]: any;
9+
}
10+
}
11+
12+
var m = <div x-y="val"></div>;
13+
var n = <div xx-y="val"></div>;
14+
var o = <div x-yy="val"></div>;
15+
var p = <div xx-yy="val"></div>;
16+
17+
// Investigation
18+
var a = <div x="val"></div>;
19+
var b = <div xx="val"></div>;
20+
var c = <div xxx="val"></div>;
21+
var d = <div xxxx="val"></div>;
22+
var e = <div xxxxx="val"></div>;

0 commit comments

Comments
 (0)