Skip to content

Commit 430c2c8

Browse files
committed
Correct flag JSX elements as being used for the purposes of module imports
1 parent e1c9d28 commit 430c2c8

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7117,6 +7117,15 @@ namespace ts {
71177117

71187118
let targetAttributesType = getJsxElementAttributesType(node);
71197119

7120+
if(getNodeLinks(node).jsxFlags & JsxFlags.ClassElement) {
7121+
if(node.tagName.kind === SyntaxKind.Identifier) {
7122+
checkIdentifier(<Identifier>node.tagName);
7123+
}
7124+
else {
7125+
checkQualifiedName(<QualifiedName>node.tagName);
7126+
}
7127+
}
7128+
71207129
let nameTable: Map<boolean> = {};
71217130
// Process this array in right-to-left order so we know which
71227131
// attributes (mostly from spreads) are being overwritten and
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
tests/cases/conformance/jsx/button.tsx(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
2+
3+
4+
==== tests/cases/conformance/jsx/react.d.ts (0 errors) ====
5+
6+
declare module 'react' {
7+
class Component<T, U> { }
8+
}
9+
10+
==== tests/cases/conformance/jsx/app.tsx (0 errors) ====
11+
import * as React from 'react';
12+
13+
// Should see var button_1 = require('./button') here
14+
import { Button } from './button';
15+
16+
export class App extends React.Component<any, any> {
17+
18+
render() {
19+
return <Button />;
20+
}
21+
22+
}
23+
24+
==== tests/cases/conformance/jsx/button.tsx (1 errors) ====
25+
import * as React from 'react';
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
!!! error TS1148: Cannot compile modules unless the '--module' flag is provided.
28+
29+
export class Button extends React.Component<any, any> {
30+
31+
render() {
32+
return <button>Some button</button>;
33+
}
34+
35+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//// [tests/cases/conformance/jsx/tsxExternalModuleEmit1.tsx] ////
2+
3+
//// [react.d.ts]
4+
5+
declare module 'react' {
6+
class Component<T, U> { }
7+
}
8+
9+
//// [app.tsx]
10+
import * as React from 'react';
11+
12+
// Should see var button_1 = require('./button') here
13+
import { Button } from './button';
14+
15+
export class App extends React.Component<any, any> {
16+
17+
render() {
18+
return <Button />;
19+
}
20+
21+
}
22+
23+
//// [button.tsx]
24+
import * as React from 'react';
25+
26+
export class Button extends React.Component<any, any> {
27+
28+
render() {
29+
return <button>Some button</button>;
30+
}
31+
32+
}
33+
34+
//// [button.jsx]
35+
var __extends = (this && this.__extends) || function (d, b) {
36+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
37+
function __() { this.constructor = d; }
38+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
39+
};
40+
var React = require('react');
41+
var Button = (function (_super) {
42+
__extends(Button, _super);
43+
function Button() {
44+
_super.apply(this, arguments);
45+
}
46+
Button.prototype.render = function () {
47+
return <button>Some button</button>;
48+
};
49+
return Button;
50+
})(React.Component);
51+
exports.Button = Button;
52+
//// [app.jsx]
53+
var __extends = (this && this.__extends) || function (d, b) {
54+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
55+
function __() { this.constructor = d; }
56+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
57+
};
58+
var React = require('react');
59+
// Should see var button_1 = require('./button') here
60+
var button_1 = require('./button');
61+
var App = (function (_super) {
62+
__extends(App, _super);
63+
function App() {
64+
_super.apply(this, arguments);
65+
}
66+
App.prototype.render = function () {
67+
return <button_1.Button />;
68+
};
69+
return App;
70+
})(React.Component);
71+
exports.App = App;

0 commit comments

Comments
 (0)