Fix tests.

This commit is contained in:
Titian Cernicova-Dragomir 2023-03-13 14:05:18 +00:00
parent 3eeef8db4b
commit 29d11008f6
5 changed files with 24 additions and 12 deletions

View File

@ -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);
}))));
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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