Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash from missing valueDeclaration on intersection property #37696

Merged
merged 3 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5964,14 +5964,18 @@ namespace ts {
];
const symbolProps = getPropertiesOfType(classType);
const publicSymbolProps = filter(symbolProps, s => {
// `valueDeclaration` could be undefined if inherited from
// a union/intersection base type, but inherited properties
// don't matter here.
const valueDecl = s.valueDeclaration;
Debug.assertIsDefined(valueDecl);
return !(isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name));
return valueDecl && !(isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name));
});
const hasPrivateIdentifier = some(symbolProps, s => {
// `valueDeclaration` could be undefined if inherited from
// a union/intersection base type, but inherited properties
// don't matter here.
const valueDecl = s.valueDeclaration;
Debug.assertIsDefined(valueDecl);
return isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name);
return valueDecl && isNamedDeclaration(valueDecl) && isPrivateIdentifier(valueDecl.name);
});
// Boil down all private properties into a single one.
const privateProperties = hasPrivateIdentifier ?
Expand Down Expand Up @@ -10314,7 +10318,7 @@ namespace ts {
if (!firstValueDeclaration) {
firstValueDeclaration = prop.valueDeclaration;
}
else if (prop.valueDeclaration !== firstValueDeclaration) {
else if (prop.valueDeclaration && prop.valueDeclaration !== firstValueDeclaration) {
hasNonUniformValueDeclaration = true;
}
declarations = addRange(declarations, prop.declarations);
Expand Down
42 changes: 42 additions & 0 deletions tests/baselines/reference/jsEmitIntersectionProperty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//// [tests/cases/compiler/jsEmitIntersectionProperty.ts] ////

//// [globals.d.ts]
// #37015 - test asserts lack of crash



declare class CoreObject {
static extend<
Statics,
Instance extends B1,
T1,
B1
>(
this: Statics & { new(): Instance },
arg1: T1
): Readonly<Statics> & { new(): T1 & Instance };

toString(): string;
}

declare class Mixin<T> {
static create<T>(
args?: T
): Mixin<T>;
}
declare const Observable: Mixin<{}>
declare class EmberObject extends CoreObject.extend(Observable) {}
declare class CoreView extends EmberObject.extend({}) {}
declare class Component extends CoreView.extend({}) {}

//// [index.js]
export class MyComponent extends Component {

}




//// [index.d.ts]
export class MyComponent extends Component {
}
4 changes: 2 additions & 2 deletions tests/baselines/reference/narrowingByTypeofInSwitch.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ function exhaustiveChecksGenerics<T extends L | R | number | string>(x: T): stri
>x : Symbol(x, Decl(narrowingByTypeofInSwitch.ts, 146, 69))

case 'number': return x.toString(2);
>x.toString : Symbol(toString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 2 more)
>x.toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 2 more)
>x : Symbol(x, Decl(narrowingByTypeofInSwitch.ts, 146, 69))
>toString : Symbol(toString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 2 more)
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --) ... and 2 more)

case 'string': return x;
>x : Symbol(x, Decl(narrowingByTypeofInSwitch.ts, 146, 69))
Expand Down
41 changes: 41 additions & 0 deletions tests/cases/compiler/jsEmitIntersectionProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// #37015 - test asserts lack of crash

// @allowJs: true
// @checkJs: true
// @declaration: true
// @emitDeclarationOnly: true
// @incremental: true
// @tsBuildInfoFile: .tsbuildinfo
// @noTypesAndSymbols: true

// @Filename: globals.d.ts

declare class CoreObject {
static extend<
Statics,
Instance extends B1,
T1,
B1
>(
this: Statics & { new(): Instance },
arg1: T1
): Readonly<Statics> & { new(): T1 & Instance };

toString(): string;
}

declare class Mixin<T> {
static create<T>(
args?: T
): Mixin<T>;
}
declare const Observable: Mixin<{}>
declare class EmberObject extends CoreObject.extend(Observable) {}
declare class CoreView extends EmberObject.extend({}) {}
declare class Component extends CoreView.extend({}) {}

// @Filename: index.js

export class MyComponent extends Component {

}