Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,15 @@ func (b *NodeBuilderImpl) serializeTypeForDeclaration(declaration *ast.Declarati
if symbol.Flags&ast.SymbolFlagsAccessor != 0 && declaration.Kind == ast.KindSetAccessor {
t = b.ch.instantiateType(b.ch.getWriteTypeOfSymbol(symbol), b.ctx.mapper)
} else if symbol != nil && (symbol.Flags&(ast.SymbolFlagsTypeLiteral|ast.SymbolFlagsSignature) == 0) {
t = b.ch.instantiateType(b.ch.getWidenedLiteralType(b.ch.getTypeOfSymbol(symbol)), b.ctx.mapper)
symType := b.ch.getTypeOfSymbol(symbol)
// Don't widen literals for export assignments — the emitted declaration is
// `const _default: <type>`, and a const should preserve the literal type.
// Strada handles this via preserveLiterals in the syntactic type builder;
// we handle it by not widening the checker type in the first place.
if !ast.IsAnyExportAssignment(declaration) {
symType = b.ch.getWidenedLiteralType(symType)
}
t = b.ch.instantiateType(symType, b.ctx.mapper)
} else {
t = b.ch.errorType
}
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/pseudotypenodebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func (b *NodeBuilderImpl) pseudoTypeToType(t *pseudochecker.PseudoType) *Type {
return b.ch.trueType
case pseudochecker.PseudoTypeKindStringLiteral, pseudochecker.PseudoTypeKindNumericLiteral, pseudochecker.PseudoTypeKindBigIntLiteral:
source := t.AsPseudoTypeLiteral().Node
return b.ch.getWidenedType(b.ch.getRegularTypeOfExpression(source)) // big shortcut, uses cached expression types where possible
return b.ch.getRegularTypeOfExpression(source) // big shortcut, uses cached expression types where possible
case pseudochecker.PseudoTypeKindObjectLiteral, pseudochecker.PseudoTypeKindSingleCallSignature, pseudochecker.PseudoTypeKindTuple:
return nil // no simple mapping to a type, since these are structural types
default:
Expand Down
2 changes: 0 additions & 2 deletions internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1584,7 +1584,6 @@ func TestTscIncremental(t *testing.T) {
edit: func(sys *TestSys) {
sys.writeFileNoError("/home/src/workspaces/project/constants.ts", "export default 2;")
},
expectedDiff: "Currently there is issue with d.ts emit for export default = 1 to widen in dts which is why we are not re-computing errors and results in incorrect error reporting",
},
},
},
Expand All @@ -1610,7 +1609,6 @@ func TestTscIncremental(t *testing.T) {
edit: func(sys *TestSys) {
sys.writeFileNoError("/home/src/workspaces/project/constants.ts", "export default 2;")
},
expectedDiff: "Currently there is issue with d.ts emit for export default = 1 to widen in dts which is why we are not re-computing errors and results in incorrect error reporting",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default class {
}
//// [exportDefaultLiteral.d.ts]
/** Literal comment */
declare const _default: number;
declare const _default: 42;
export default _default;
//// [exportDefaultNull.d.ts]
/** Null comment */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class {
}
//// [exportDefaultLiteral.d.ts]
/** Literal comment */
declare const _default: number;
declare const _default: 42;
export default _default;
//// [exportDefaultNull.d.ts]
/** Null comment */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ exports.mod = await (async () => {


//// [case0.d.ts]
declare const _default: number;
declare const _default: 0;
export default _default;
//// [case1.d.ts]
declare const _default: number;
declare const _default: 1;
export default _default;
//// [caseFallback.d.ts]
declare const _default: string;
declare const _default: "fallback";
export default _default;
//// [index.d.ts]
export declare const mod: {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export {}; // Silly test harness
//// [a.d.ts]
export declare const x = 0;
//// [b.d.ts]
declare const _default: number;
declare const _default: 0;
export default _default;
//// [c.d.ts]
declare const _default: {
Expand All @@ -208,10 +208,10 @@ export = _default;
declare const _default: () => void;
export = _default;
//// [e.d.mts]
declare const _default: number;
declare const _default: 0;
export = _default;
//// [f.d.cts]
declare const _default: number;
declare const _default: 0;
export default _default;
//// [g.d.ts]
declare const _default: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,9 @@
-export const x: 0;
+export declare const x = 0;
//// [b.d.ts]
-declare const _default: 0;
+declare const _default: number;
export default _default;
//// [c.d.ts]
declare const _default: {
@@= skipped -13, +13 lines =@@
declare const _default: () => void;
export = _default;
//// [e.d.mts]
-declare const _default: 0;
+declare const _default: number;
export = _default;
//// [f.d.cts]
-declare const _default: 0;
+declare const _default: number;
export default _default;
//// [g.d.ts]
declare const _default: 0;
@@= skipped -15, +15 lines =@@
export default _default;
@@= skipped -28, +28 lines =@@
//// [main3.d.cts]
export {};
//// [main4.d.cts]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ns.default.a;

//// [a.d.cts]
export declare const a: number;
declare const _default: string;
declare const _default: "string";
export default _default;
//// [foo.d.mts]
import d, { a } from './a.cjs';
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function func() { }


//// [index1.d.ts]
declare const _default: number;
declare const _default: 12;
export default _default;
//// [index2.d.ts]
export default function foo(): typeof foo;
Expand All @@ -120,7 +120,7 @@ declare class Bar extends Fab {
}
export default Bar;
//// [index5.d.ts]
declare const _default: number;
declare const _default: 12;
export default _default;
export type default = string | number;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
--- old.jsDeclarationsDefault(target=es2015).js
+++ new.jsDeclarationsDefault(target=es2015).js
@@= skipped -100, +100 lines =@@


//// [index1.d.ts]
-declare const _default: 12;
+declare const _default: number;
@@= skipped -104, +104 lines =@@
export default _default;
//// [index2.d.ts]
export default function foo(): typeof foo;
Expand All @@ -29,8 +24,7 @@
+export default Bar;
//// [index5.d.ts]
-type _default = string | number;
-declare const _default: 12;
+declare const _default: number;
declare const _default: 12;
export default _default;
+export type default = string | number;
+/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tsgo
ExitStatus:: Success
Output::
//// [/home/src/projects/project/src/main.d.ts] *new*
declare const _default: number;
declare const _default: 42;
export default _default;

//// [/home/src/projects/project/src/main.js] *new*
Expand All @@ -35,7 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.default = 42;

//// [/home/src/projects/project/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2025.full.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"00e459cbb1596f8c4bdf988b0589433f-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}","impliedNodeFormat":99},{"version":"666fdc0c7a7f134c8c14dc85be1ebc28-export default 42;","signature":"18ae69a2c0b372747b9973ad9c14a1e0-declare const _default: number;\nexport default _default;\n","impliedNodeFormat":1}],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"latestChangedDtsFile":"./src/main.d.ts"}
{"version":"FakeTSVersion","root":[3],"fileNames":["lib.es2025.full.d.ts","./node_modules/solid-js/jsx-runtime.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"00e459cbb1596f8c4bdf988b0589433f-export namespace JSX {\n type IntrinsicElements = { div: {}; };\n}","impliedNodeFormat":99},{"version":"666fdc0c7a7f134c8c14dc85be1ebc28-export default 42;","signature":"e48ca0859b14891cbeb31bf4dec89530-declare const _default: 42;\nexport default _default;\n","impliedNodeFormat":1}],"options":{"composite":true,"jsx":4,"jsxImportSource":"solid-js","module":100},"latestChangedDtsFile":"./src/main.d.ts"}
//// [/home/src/projects/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
Expand Down Expand Up @@ -78,11 +78,11 @@ exports.default = 42;
{
"fileName": "./src/main.ts",
"version": "666fdc0c7a7f134c8c14dc85be1ebc28-export default 42;",
"signature": "18ae69a2c0b372747b9973ad9c14a1e0-declare const _default: number;\nexport default _default;\n",
"signature": "e48ca0859b14891cbeb31bf4dec89530-declare const _default: 42;\nexport default _default;\n",
"impliedNodeFormat": "CommonJS",
"original": {
"version": "666fdc0c7a7f134c8c14dc85be1ebc28-export default 42;",
"signature": "18ae69a2c0b372747b9973ad9c14a1e0-declare const _default: number;\nexport default _default;\n",
"signature": "e48ca0859b14891cbeb31bf4dec89530-declare const _default: 42;\nexport default _default;\n",
"impliedNodeFormat": 1
}
}
Expand All @@ -94,7 +94,7 @@ exports.default = 42;
"module": 100
},
"latestChangedDtsFile": "./src/main.d.ts",
"size": 1373
"size": 1369
}
//// [/home/src/tslibs/TS/Lib/lib.es2025.full.d.ts] *Lib*
/// <reference no-default-lib="true"/>
Expand Down
Loading
Loading