From 29d11008f6c76884b34f8fb13deb5273da601c61 Mon Sep 17 00:00:00 2001 From: Titian Cernicova-Dragomir Date: Mon, 13 Mar 2023 14:05:18 +0000 Subject: [PATCH] Fix tests. --- src/compiler/transformers/declarations.ts | 14 ++++++++++---- .../importsNotUsedAsValues_error.errors.txt | 7 +++++-- .../reference/importsNotUsedAsValues_error.js | 7 +++++-- .../reference/importsNotUsedAsValues_error.symbols | 4 ++-- .../reference/importsNotUsedAsValues_error.types | 4 ++-- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 0658da726cf..6d12eed35cb 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -756,7 +756,7 @@ export function transformDeclarations(context: TransformationContext) { function ensureNoInitializer(node: CanHaveLiteralInitializer) { if (shouldPrintWithInitializer(node)) { - if(node.initializer && isLiteralExpression(node.initializer)) { + if(isolatedDeclarations && node.initializer && isLiteralExpression(node.initializer)) { return node.initializer; } return resolver.createLiteralConstValue(getParseTreeNode(node) as CanHaveLiteralInitializer, symbolTracker); // TODO: Make safe @@ -1130,7 +1130,7 @@ export function transformDeclarations(context: TransformationContext) { if (isDeclaration(input)) { if (isDeclarationAndNotVisible(input)) return; if (hasDynamicName(input) && !resolver.isLateBound(getParseTreeNode(input) as Declaration)) { - if (hasIdentifierComputedName(input)) { + if (isolatedDeclarations && hasIdentifierComputedName(input)) { reportIsolatedDeclarationError(input); } else { @@ -1734,7 +1734,7 @@ export function transformDeclarations(context: TransformationContext) { if (extendsClause && !isEntityNameExpression(extendsClause.expression) && extendsClause.expression.kind !== SyntaxKind.NullKeyword) { // We must add a temporary declaration for the extends clause expression - // Isolated declarations do not allow inferred type in the extends clause + // Isolated declarations does not allow inferred type in the extends clause if(isolatedDeclarations) { reportIsolatedDeclarationError(extendsClause); return cleanup(factory.updateClassDeclaration( @@ -1798,8 +1798,14 @@ export function transformDeclarations(context: TransformationContext) { case SyntaxKind.EnumDeclaration: { return cleanup(factory.updateEnumDeclaration(input, factory.createNodeArray(ensureModifiers(input)), input.name, factory.createNodeArray(mapDefined(input.members, m => { if (shouldStripInternal(m)) return; + if (isolatedDeclarations) { + if (m.initializer && !isLiteralExpression(m.initializer)) { + reportIsolatedDeclarationError(m); + } + return m; + } // Rewrite enum values to their constants, if available - const constValue = isolatedDeclarations? undefined : resolver.getConstantValue(m); + const constValue = resolver.getConstantValue(m); return preserveJsDoc(factory.updateEnumMember(m, m.name, constValue !== undefined ? typeof constValue === "string" ? factory.createStringLiteral(constValue) : factory.createNumericLiteral(constValue) : undefined), m); })))); } diff --git a/tests/baselines/reference/importsNotUsedAsValues_error.errors.txt b/tests/baselines/reference/importsNotUsedAsValues_error.errors.txt index dd2eda5644c..1c9d69752e2 100644 --- a/tests/baselines/reference/importsNotUsedAsValues_error.errors.txt +++ b/tests/baselines/reference/importsNotUsedAsValues_error.errors.txt @@ -5,6 +5,7 @@ error TS5101: Option 'importsNotUsedAsValues' is deprecated and will stop functi /e.ts(1,1): error TS6192: All imports in import declaration are unused. /g.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'. /i.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'. +/j.ts(1,8): error TS6133: 'H' is declared but its value is never read. !!! error TS5101: Option 'importsNotUsedAsValues' is deprecated and will stop functioning in TypeScript 5.5. Specify compilerOption '"ignoreDeprecations": "5.0"' to silence this error. @@ -69,8 +70,10 @@ error TS5101: Option 'importsNotUsedAsValues' is deprecated and will stop functi let h: H = {}; console.log(h); -==== /j.ts (0 errors) ==== +==== /j.ts (1 errors) ==== import H = require('./h'); // noUnusedLocals error only + ~ +!!! error TS6133: 'H' is declared but its value is never read. ==== /k.ts (0 errors) ==== const enum K { One, Two } @@ -80,5 +83,5 @@ error TS5101: Option 'importsNotUsedAsValues' is deprecated and will stop functi import K = require('./k'); K.One; -==== /j.ts (0 errors) ==== +==== /m.ts (0 errors) ==== // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 \ No newline at end of file diff --git a/tests/baselines/reference/importsNotUsedAsValues_error.js b/tests/baselines/reference/importsNotUsedAsValues_error.js index 0d3b2faa91f..9a5d3c5322d 100644 --- a/tests/baselines/reference/importsNotUsedAsValues_error.js +++ b/tests/baselines/reference/importsNotUsedAsValues_error.js @@ -61,7 +61,7 @@ export = K; import K = require('./k'); K.One; -//// [j.ts] +//// [m.ts] // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 //// [a.js] @@ -134,7 +134,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); var h = {}; console.log(h); //// [j.js] -// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); //// [k.js] "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); @@ -142,3 +143,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 /* K.One */; +//// [m.js] +// Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 diff --git a/tests/baselines/reference/importsNotUsedAsValues_error.symbols b/tests/baselines/reference/importsNotUsedAsValues_error.symbols index 4cd9d40aec3..985050e04d8 100644 --- a/tests/baselines/reference/importsNotUsedAsValues_error.symbols +++ b/tests/baselines/reference/importsNotUsedAsValues_error.symbols @@ -154,8 +154,8 @@ console.log(h); >h : Symbol(h, Decl(i.ts, 1, 3)) === /j.ts === - import H = require('./h'); // noUnusedLocals error only +>H : Symbol(H, Decl(j.ts, 0, 0)) === /k.ts === const enum K { One, Two } @@ -175,6 +175,6 @@ K.One; >K : Symbol(K, Decl(l.ts, 0, 0)) >One : Symbol(K.One, Decl(k.ts, 0, 14)) -=== /j.ts === +=== /m.ts === // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207 diff --git a/tests/baselines/reference/importsNotUsedAsValues_error.types b/tests/baselines/reference/importsNotUsedAsValues_error.types index e3d06b246c1..0c3c158c81f 100644 --- a/tests/baselines/reference/importsNotUsedAsValues_error.types +++ b/tests/baselines/reference/importsNotUsedAsValues_error.types @@ -151,8 +151,8 @@ console.log(h); >h : H === /j.ts === - import H = require('./h'); // noUnusedLocals error only +>H : typeof H === /k.ts === const enum K { One, Two } @@ -172,6 +172,6 @@ K.One; >K : typeof K >One : K.One -=== /j.ts === +=== /m.ts === // Sad face https://github.com/microsoft/TypeScript/blob/6b04f5039429b9d412696fe2febe39ecc69ad365/src/testRunner/compilerRunner.ts#L207