Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ func (n *Node) Initializer() *Node {
return n.AsForInOrOfStatement().Initializer
case KindJsxAttribute:
return n.AsJsxAttribute().Initializer
case KindCommonJSExport:
return n.AsCommonJSExport().Initializer
}
panic("Unhandled case in Node.Initializer")
}
Expand Down Expand Up @@ -806,6 +808,8 @@ func (m *mutableNode) SetInitializer(initializer *Node) {
n.AsForInOrOfStatement().Initializer = initializer
case KindJsxAttribute:
n.AsJsxAttribute().Initializer = initializer
case KindCommonJSExport:
n.AsCommonJSExport().Initializer = initializer
default:
panic("Unhandled case in mutableNode.SetInitializer")
}
Expand Down
5 changes: 3 additions & 2 deletions internal/parser/reparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node)
}
}
case ast.KindVariableDeclaration,
ast.KindCommonJSExport, ast.KindExportAssignment, ast.KindJSExportAssignment,
ast.KindCommonJSExport,
ast.KindPropertyDeclaration, ast.KindPropertyAssignment, ast.KindShorthandPropertyAssignment:
if parent.Initializer() != nil && tag.AsJSDocSatisfiesTag().TypeExpression != nil {
parent.AsMutable().SetInitializer(p.makeNewCast(
Expand All @@ -366,7 +366,8 @@ func (p *Parser) reparseHosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Node)
false /*isAssertion*/))
p.finishMutatedNode(parent)
}
case ast.KindReturnStatement, ast.KindParenthesizedExpression:
case ast.KindReturnStatement, ast.KindParenthesizedExpression,
ast.KindExportAssignment, ast.KindJSExportAssignment:
if parent.Expression() != nil && tag.AsJSDocSatisfiesTag().TypeExpression != nil {
parent.AsMutable().SetExpression(p.makeNewCast(
p.factory.DeepCloneReparse(tag.AsJSDocSatisfiesTag().TypeExpression.Type()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
panicSatisfiesOnExportEqualsDeclaration.js(2,14): error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.
panicSatisfiesOnExportEqualsDeclaration.js(5,23): error TS2307: Cannot find module './types' or its corresponding type declarations.


==== types.d.ts (0 errors) ====
export interface SupportVersionTraceMap {
zlib?: any;
'node:zlib'?: any;
}

==== panicSatisfiesOnExportEqualsDeclaration.js (2 errors) ====
const zlib = {};
const READ = Symbol('read');
~~~~~~
!!! error TS2585: 'Symbol' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the 'lib' compiler option to es2015 or later.

/**
* @satisfies {import('./types').SupportVersionTraceMap}
~~~~~~~~~
!!! error TS2307: Cannot find module './types' or its corresponding type declarations.
*/
module.exports = {
zlib: zlib,
'node:zlib': {
...zlib,
[READ]: { supported: ['14.13.1', '12.20.0'] },
},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//// [tests/cases/compiler/panicSatisfiesOnExportEqualsDeclaration.ts] ////

=== types.d.ts ===
export interface SupportVersionTraceMap {
>SupportVersionTraceMap : Symbol(SupportVersionTraceMap, Decl(types.d.ts, 0, 0))

zlib?: any;
>zlib : Symbol(SupportVersionTraceMap.zlib, Decl(types.d.ts, 0, 41))

'node:zlib'?: any;
>'node:zlib' : Symbol(SupportVersionTraceMap["node:zlib"], Decl(types.d.ts, 1, 15))
}

=== panicSatisfiesOnExportEqualsDeclaration.js ===
const zlib = {};
>zlib : Symbol(zlib, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 5))

const READ = Symbol('read');
>READ : Symbol(READ, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 1, 5))

/**
* @satisfies {import('./types').SupportVersionTraceMap}
*/
module.exports = {
>module.exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 1, 28))
>module : Symbol(module.exports)
>exports : Symbol(export=, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 1, 28))

zlib: zlib,
>zlib : Symbol(zlib, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 6, 18))
>zlib : Symbol(zlib, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 5))

'node:zlib': {
>'node:zlib' : Symbol('node:zlib', Decl(panicSatisfiesOnExportEqualsDeclaration.js, 7, 15))

...zlib,
>zlib : Symbol(zlib, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 0, 5))

[READ]: { supported: ['14.13.1', '12.20.0'] },
>[READ] : Symbol([READ], Decl(panicSatisfiesOnExportEqualsDeclaration.js, 9, 16))
>READ : Symbol(READ, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 1, 5))
>supported : Symbol(supported, Decl(panicSatisfiesOnExportEqualsDeclaration.js, 10, 17))

},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//// [tests/cases/compiler/panicSatisfiesOnExportEqualsDeclaration.ts] ////

=== types.d.ts ===
export interface SupportVersionTraceMap {
zlib?: any;
>zlib : any

'node:zlib'?: any;
>'node:zlib' : any
}

=== panicSatisfiesOnExportEqualsDeclaration.js ===
const zlib = {};
>zlib : {}
>{} : {}

const READ = Symbol('read');
>READ : any
>Symbol('read') : any
>Symbol : any
>'read' : "read"

/**
* @satisfies {import('./types').SupportVersionTraceMap}
*/
module.exports = {
>module.exports = { zlib: zlib, 'node:zlib': { ...zlib, [READ]: { supported: ['14.13.1', '12.20.0'] }, },} : any
>module.exports : any
>module : { "export=": any; }
>exports : any
>{ zlib: zlib, 'node:zlib': { ...zlib, [READ]: { supported: ['14.13.1', '12.20.0'] }, },} : { zlib: {}; "node:zlib": {}; }

zlib: zlib,
>zlib : {}
>zlib : {}

'node:zlib': {
>'node:zlib' : {}
>{ ...zlib, [READ]: { supported: ['14.13.1', '12.20.0'] }, } : {}

...zlib,
>zlib : {}

[READ]: { supported: ['14.13.1', '12.20.0'] },
>[READ] : { supported: string[]; }
>READ : any
>{ supported: ['14.13.1', '12.20.0'] } : { supported: string[]; }
>supported : string[]
>['14.13.1', '12.20.0'] : string[]
>'14.13.1' : "14.13.1"
>'12.20.0' : "12.20.0"

},
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @module: commonjs
// @Filename: types.d.ts
export interface SupportVersionTraceMap {
zlib?: any;
'node:zlib'?: any;
}

// @Filename: panicSatisfiesOnExportEqualsDeclaration.js
const zlib = {};
const READ = Symbol('read');

/**
* @satisfies {import('./types').SupportVersionTraceMap}
*/
module.exports = {
zlib: zlib,
'node:zlib': {
...zlib,
[READ]: { supported: ['14.13.1', '12.20.0'] },
},
};
Loading