diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d3f15f2367b..a4d53c40d4d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11070,14 +11070,20 @@ namespace ts { function checkJsxOpeningLikeElement(node: JsxOpeningLikeElement) { checkGrammarJsxElement(node); checkJsxPreconditions(node); - // The reactNamespace symbol should be marked as 'used' so we don't incorrectly elide its import. And if there // is no reactNamespace symbol in scope when targeting React emit, we should issue an error. const reactRefErr = compilerOptions.jsx === JsxEmit.React ? Diagnostics.Cannot_find_name_0 : undefined; const reactNamespace = compilerOptions.reactNamespace ? compilerOptions.reactNamespace : "React"; const reactSym = resolveName(node.tagName, reactNamespace, SymbolFlags.Value, reactRefErr, reactNamespace); if (reactSym) { - getSymbolLinks(reactSym).referenced = true; + // Mark local symbol as referenced here because it might not have been marked + // if jsx emit was not react as there wont be error being emitted + reactSym.isReferenced = true; + + // If react symbol is alias, mark it as refereced + if (reactSym.flags & SymbolFlags.Alias && !isConstEnumOrConstEnumOnlyModule(resolveAlias(reactSym))) { + markAliasSymbolAsReferenced(reactSym); + } } const targetAttributesType = getJsxElementAttributesType(node); diff --git a/tests/baselines/reference/unusedImports13.errors.txt b/tests/baselines/reference/unusedImports13.errors.txt deleted file mode 100644 index 0e870795eb6..00000000000 --- a/tests/baselines/reference/unusedImports13.errors.txt +++ /dev/null @@ -1,25 +0,0 @@ -tests/cases/compiler/foo.tsx(2,8): error TS6133: 'React' is declared but never used. - - -==== tests/cases/compiler/foo.tsx (1 errors) ==== - - import React = require("react"); - ~~~~~ -!!! error TS6133: 'React' is declared but never used. - - export const FooComponent =
- -==== tests/cases/compiler/node_modules/@types/react/index.d.ts (0 errors) ==== - export = React; - export as namespace React; - - declare namespace React { - function createClass(spec); - } - declare global { - namespace JSX { - } - } - - - \ No newline at end of file diff --git a/tests/baselines/reference/unusedImports13.symbols b/tests/baselines/reference/unusedImports13.symbols new file mode 100644 index 00000000000..3ac44d17533 --- /dev/null +++ b/tests/baselines/reference/unusedImports13.symbols @@ -0,0 +1,36 @@ +=== tests/cases/compiler/foo.tsx === + +import React = require("react"); +>React : Symbol(React, Decl(foo.tsx, 0, 0)) + +export const FooComponent =
+>FooComponent : Symbol(FooComponent, Decl(foo.tsx, 3, 12)) +>div : Symbol(unknown) +>div : Symbol(unknown) + +=== tests/cases/compiler/node_modules/@types/react/index.d.ts === +export = React; +>React : Symbol(React, Decl(index.d.ts, 1, 26)) + +export as namespace React; +>React : Symbol(React, Decl(index.d.ts, 0, 15)) + +declare namespace React { +>React : Symbol(React, Decl(index.d.ts, 1, 26)) + + function createClass(spec); +>createClass : Symbol(createClass, Decl(index.d.ts, 3, 25)) +>P : Symbol(P, Decl(index.d.ts, 4, 25)) +>S : Symbol(S, Decl(index.d.ts, 4, 27)) +>spec : Symbol(spec, Decl(index.d.ts, 4, 31)) +} +declare global { +>global : Symbol(global, Decl(index.d.ts, 5, 1)) + + namespace JSX { +>JSX : Symbol(JSX, Decl(index.d.ts, 6, 16)) + } +} + + + diff --git a/tests/baselines/reference/unusedImports13.types b/tests/baselines/reference/unusedImports13.types new file mode 100644 index 00000000000..b19531b3e2d --- /dev/null +++ b/tests/baselines/reference/unusedImports13.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/foo.tsx === + +import React = require("react"); +>React : typeof React + +export const FooComponent =
+>FooComponent : any +>
: any +>div : any +>div : any + +=== tests/cases/compiler/node_modules/@types/react/index.d.ts === +export = React; +>React : typeof React + +export as namespace React; +>React : typeof React + +declare namespace React { +>React : typeof React + + function createClass(spec); +>createClass : (spec: any) => any +>P : P +>S : S +>spec : any +} +declare global { +>global : any + + namespace JSX { +>JSX : any + } +} + + +