Skip to content

Commit 9dc7b92

Browse files
committed
avoid adding declaration for invalid js
1 parent bcfb377 commit 9dc7b92

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,10 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
34303430
}
34313431

34323432
function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) {
3433+
if (isInJSFile(node) && (node.flags & NodeFlags.Ambient)) {
3434+
return;
3435+
}
3436+
34333437
if (!file.isDeclarationFile && !(node.flags & NodeFlags.Ambient) && isAsyncFunction(node)) {
34343438
emitFlags |= NodeFlags.HasAsyncFunctions;
34353439
}

src/compiler/checker.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9567,13 +9567,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
95679567
}
95689568
if (!type) {
95699569
let types: Type[] | undefined;
9570-
let declarations: Declaration[] | undefined;
95719570
if (symbol.declarations) {
95729571
let jsdocType: Type | undefined;
95739572
for (const declaration of symbol.declarations) {
9574-
if (isInJSFile(declaration) && hasSyntacticModifier(declaration, ModifierFlags.Ambient)) {
9575-
continue;
9576-
}
95779573
const expression = (isBinaryExpression(declaration) || isCallExpression(declaration)) ? declaration :
95789574
isAccessExpression(declaration) ? isBinaryExpression(declaration.parent) ? declaration.parent : declaration :
95799575
undefined;
@@ -9597,15 +9593,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
95979593
if (!jsdocType) {
95989594
(types ??= []).push((isBinaryExpression(expression) || isCallExpression(expression)) ? getInitializerTypeFromAssignmentDeclaration(symbol, resolvedSymbol, expression, kind) : neverType);
95999595
}
9600-
(declarations ??= []).push(declaration);
96019596
}
96029597
type = jsdocType;
96039598
}
96049599
if (!type) {
96059600
if (!length(types)) {
96069601
return errorType; // No types from any declarations :(
96079602
}
9608-
let constructorTypes = definedInConstructor && declarations ? getConstructorDefinedThisAssignmentTypes(types!, declarations) : undefined;
9603+
let constructorTypes = definedInConstructor && symbol.declarations ? getConstructorDefinedThisAssignmentTypes(types!, symbol.declarations) : undefined;
96099604
// use only the constructor types unless they were only assigned null | undefined (including widening variants)
96109605
if (definedInMethod) {
96119606
const propType = getTypeOfPropertyInBaseClass(symbol);

0 commit comments

Comments
 (0)