Skip to content

Commit

Permalink
Fix crash from missing valueDeclaration on intersection property (#37696
Browse files Browse the repository at this point in the history
)

* Add crashing test

* Fix missing valueDeclaration on intersection symbol property

* Remove assertion from serializeAsClass
  • Loading branch information
andrewbranch committed Apr 9, 2020
1 parent 4a646c9 commit 95cc1c2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6211,14 +6211,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 @@ -10420,7 +10424,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 {

}

0 comments on commit 95cc1c2

Please sign in to comment.