Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2512,11 +2512,10 @@ namespace ts {

function bindPropertyAssignment(name: EntityNameExpression, propertyAccess: PropertyAccessEntityNameExpression, isPrototypeProperty: boolean) {
let namespaceSymbol = lookupSymbolForPropertyAccess(name);
const isToplevelNamespaceableInitializer = isBinaryExpression(propertyAccess.parent)
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile &&
!!getJavascriptInitializer(getInitializerOfBinaryExpression(propertyAccess.parent), isPrototypeAccess(propertyAccess.parent.left))
const isToplevel = isBinaryExpression(propertyAccess.parent)
? getParentOfBinaryExpression(propertyAccess.parent).parent.kind === SyntaxKind.SourceFile
: propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevelNamespaceableInitializer) {
if (!isPrototypeProperty && (!namespaceSymbol || !(namespaceSymbol.flags & SymbolFlags.Namespace)) && isToplevel) {
// make symbols or add declarations for intermediate containers
const flags = SymbolFlags.Module | SymbolFlags.JSContainer;
const excludeFlags = SymbolFlags.ValueModuleExcludes & ~SymbolFlags.JSContainer;
Expand Down Expand Up @@ -2573,7 +2572,7 @@ namespace ts {
return false;
}

function getParentOfBinaryExpression(expr: BinaryExpression) {
function getParentOfBinaryExpression(expr: Node) {
while (isBinaryExpression(expr.parent)) {
expr = expr.parent;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16189,7 +16189,7 @@ namespace ts {
else if (isIdentifier(lhs.expression)) {
const id = lhs.expression;
const parentSymbol = resolveName(id, id.escapedText, SymbolFlags.Value, undefined, id.escapedText, /*isUse*/ true);
if (parentSymbol && isFunctionSymbol(parentSymbol)) {
if (parentSymbol) {
const annotated = getEffectiveTypeAnnotationNode(parentSymbol.valueDeclaration);
if (annotated) {
const type = getTypeOfPropertyOfContextualType(getTypeFromTypeNode(annotated), lhs.name.escapedText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var lol = "hello Lol"
>lol : Symbol(lol, Decl(0.js, 1, 3))

const obj = {
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))

/** @type {string|undefined} */
foo: undefined,
Expand Down Expand Up @@ -40,31 +40,31 @@ const obj = {
}
obj.foo = 'string'
>obj.foo : Symbol(foo, Decl(0.js, 2, 13))
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))
>foo : Symbol(foo, Decl(0.js, 2, 13))

obj.lol
>obj.lol : Symbol(lol, Decl(0.js, 10, 4))
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))
>lol : Symbol(lol, Decl(0.js, 10, 4))

obj.bar = undefined;
>obj.bar : Symbol(bar, Decl(0.js, 4, 17))
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))
>bar : Symbol(bar, Decl(0.js, 4, 17))
>undefined : Symbol(undefined)

var k = obj.method1(0);
>k : Symbol(k, Decl(0.js, 21, 3))
>obj.method1 : Symbol(method1, Decl(0.js, 6, 12))
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))
>method1 : Symbol(method1, Decl(0.js, 6, 12))

obj.bar1 = "42";
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))

obj.arrowFunc(0);
>obj.arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))
>obj : Symbol(obj, Decl(0.js, 2, 5))
>obj : Symbol(obj, Decl(0.js, 2, 5), Decl(0.js, 17, 1))
>arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))

Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ class Sql extends Wagon {
}
}
var db = new Sql();
>db : Symbol(db, Decl(first.js, 42, 3))
>db : Symbol(db, Decl(first.js, 42, 3), Decl(first.js, 42, 19))
>Sql : Symbol(Sql, Decl(first.js, 18, 1))

db.numberOxen = db.foonly
>db.numberOxen : Symbol(Wagon.numberOxen, Decl(first.js, 4, 28))
>db : Symbol(db, Decl(first.js, 42, 3))
>db : Symbol(db, Decl(first.js, 42, 3), Decl(first.js, 42, 19))
>numberOxen : Symbol(Wagon.numberOxen, Decl(first.js, 4, 28))
>db.foonly : Symbol(Sql.foonly, Decl(first.js, 22, 16))
>db : Symbol(db, Decl(first.js, 42, 3))
>db : Symbol(db, Decl(first.js, 42, 3), Decl(first.js, 42, 19))
>foonly : Symbol(Sql.foonly, Decl(first.js, 22, 16))

// error, can't extend a TS constructor function
Expand Down
14 changes: 7 additions & 7 deletions tests/baselines/reference/constructorFunctions3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ i;
>i : Symbol(i, Decl(a.js, 3, 3))

function StaticToo() {
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2), Decl(a.js, 9, 1))

this.i = 'more complex'
>i : Symbol(StaticToo.i, Decl(a.js, 7, 22))
}
StaticToo.property = 'yep'
>StaticToo.property : Symbol(StaticToo.property, Decl(a.js, 9, 1))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2), Decl(a.js, 9, 1))
>property : Symbol(StaticToo.property, Decl(a.js, 9, 1))

var s = new StaticToo();
>s : Symbol(s, Decl(a.js, 11, 3))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2), Decl(a.js, 9, 1))

s;
>s : Symbol(s, Decl(a.js, 11, 3))

StaticToo;
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2))
>StaticToo : Symbol(StaticToo, Decl(a.js, 5, 2), Decl(a.js, 9, 1))

// Both!
function A () {
Expand Down Expand Up @@ -74,12 +74,12 @@ A.t = function g(m) {
>m : Symbol(m, Decl(a.js, 26, 17))
}
var a = new A()
>a : Symbol(a, Decl(a.js, 29, 3))
>a : Symbol(a, Decl(a.js, 29, 3), Decl(a.js, 31, 6))
>A : Symbol(A, Decl(a.js, 13, 10), Decl(a.js, 24, 1))

a.z(3)
>a.z : Symbol(A.z, Decl(a.js, 20, 1))
>a : Symbol(a, Decl(a.js, 29, 3))
>a : Symbol(a, Decl(a.js, 29, 3), Decl(a.js, 31, 6))
>z : Symbol(A.z, Decl(a.js, 20, 1))

A.t(2)
Expand All @@ -89,6 +89,6 @@ A.t(2)

a.second = 1
>a.second : Symbol(A.second, Decl(a.js, 17, 14))
>a : Symbol(a, Decl(a.js, 29, 3))
>a : Symbol(a, Decl(a.js, 29, 3), Decl(a.js, 31, 6))
>second : Symbol(A.second, Decl(a.js, 17, 14))

6 changes: 3 additions & 3 deletions tests/baselines/reference/constructorFunctionsStrict.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ C.prototype.m = function() {
>y : Symbol(C.y, Decl(a.js, 4, 28))
}
var c = new C(1)
>c : Symbol(c, Decl(a.js, 7, 3))
>c : Symbol(c, Decl(a.js, 7, 3), Decl(a.js, 7, 16))
>C : Symbol(C, Decl(a.js, 0, 0))

c.x = undefined // should error
>c.x : Symbol(C.x, Decl(a.js, 1, 15))
>c : Symbol(c, Decl(a.js, 7, 3))
>c : Symbol(c, Decl(a.js, 7, 3), Decl(a.js, 7, 16))
>x : Symbol(C.x, Decl(a.js, 1, 15))
>undefined : Symbol(undefined)

c.y = undefined // ok
>c.y : Symbol(C.y, Decl(a.js, 4, 28))
>c : Symbol(c, Decl(a.js, 7, 3))
>c : Symbol(c, Decl(a.js, 7, 3), Decl(a.js, 7, 16))
>y : Symbol(C.y, Decl(a.js, 4, 28))
>undefined : Symbol(undefined)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

// property assignment
var ns = {}
>ns : Symbol(ns, Decl(test.js, 6, 3))
>ns : Symbol(ns, Decl(test.js, 6, 3), Decl(test.js, 6, 11))

/** @type {DoneStatus} */
ns.x = {
>ns.x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))
>ns : Symbol(ns, Decl(test.js, 6, 3))
>ns : Symbol(ns, Decl(test.js, 6, 3), Decl(test.js, 6, 11))
>x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))

status: 'done',
Expand All @@ -24,7 +24,7 @@ ns.x = {

ns.x = {
>ns.x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))
>ns : Symbol(ns, Decl(test.js, 6, 3))
>ns : Symbol(ns, Decl(test.js, 6, 3), Decl(test.js, 6, 11))
>x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))

status: 'done',
Expand All @@ -36,7 +36,7 @@ ns.x = {
}
ns.x
>ns.x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))
>ns : Symbol(ns, Decl(test.js, 6, 3))
>ns : Symbol(ns, Decl(test.js, 6, 3), Decl(test.js, 6, 11))
>x : Symbol(ns.x, Decl(test.js, 6, 11), Decl(test.js, 11, 1))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

// property assignment
var ns = {}
>ns : { x: { status: "done"; m(n: number): void; }; }
>ns : typeof ns
>{} : {}

/** @type {DoneStatus} */
ns.x = {
>ns.x = { status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }
>ns.x : { status: "done"; m(n: number): void; }
>ns : { x: { status: "done"; m(n: number): void; }; }
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }
>{ status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }

Expand All @@ -29,7 +29,7 @@ ns.x = {
ns.x = {
>ns.x = { status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }
>ns.x : { status: "done"; m(n: number): void; }
>ns : { x: { status: "done"; m(n: number): void; }; }
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }
>{ status: 'done', m(n) { }} : { status: "done"; m(n: number): void; }

Expand All @@ -43,7 +43,7 @@ ns.x = {
}
ns.x
>ns.x : { status: "done"; m(n: number): void; }
>ns : { x: { status: "done"; m(n: number): void; }; }
>ns : typeof ns
>x : { status: "done"; m(n: number): void; }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ interface StatelessComponent<P> {
}

const MyComponent: StatelessComponent<MyComponentProps> = () => null as any;
>MyComponent : Symbol(MyComponent, Decl(expandoFunctionContextualTypes.ts, 9, 5))
>MyComponent : Symbol(MyComponent, Decl(expandoFunctionContextualTypes.ts, 9, 5), Decl(expandoFunctionContextualTypes.ts, 9, 76))
>StatelessComponent : Symbol(StatelessComponent, Decl(expandoFunctionContextualTypes.ts, 2, 1))
>MyComponentProps : Symbol(MyComponentProps, Decl(expandoFunctionContextualTypes.ts, 0, 0))

MyComponent.defaultProps = {
>MyComponent.defaultProps : Symbol(StatelessComponent.defaultProps, Decl(expandoFunctionContextualTypes.ts, 5, 12))
>MyComponent : Symbol(MyComponent, Decl(expandoFunctionContextualTypes.ts, 9, 5))
>MyComponent : Symbol(MyComponent, Decl(expandoFunctionContextualTypes.ts, 9, 5), Decl(expandoFunctionContextualTypes.ts, 9, 76))
>defaultProps : Symbol(StatelessComponent.defaultProps, Decl(expandoFunctionContextualTypes.ts, 5, 12))

color: "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* @type {StatelessComponent<MyComponentProps>}
*/
const MyComponent = () => /* @type {any} */(null);
>MyComponent : Symbol(MyComponent, Decl(input.js, 9, 5))
>MyComponent : Symbol(MyComponent, Decl(input.js, 9, 5), Decl(input.js, 9, 50))

MyComponent.defaultProps = {
>MyComponent.defaultProps : Symbol(defaultProps, Decl(input.js, 4, 23))
>MyComponent : Symbol(MyComponent, Decl(input.js, 9, 5))
>MyComponent : Symbol(MyComponent, Decl(input.js, 9, 5), Decl(input.js, 9, 50))
>defaultProps : Symbol(defaultProps, Decl(input.js, 4, 23))

color: "red"
Expand All @@ -22,14 +22,14 @@ MyComponent.defaultProps = {
};

const MyComponent2 = () => null;
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5))
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5), Decl(input.js, 15, 32))

/**
* @type {MyComponentProps}
*/
MyComponent2.defaultProps = {
>MyComponent2.defaultProps : Symbol(MyComponent2.defaultProps, Decl(input.js, 15, 32))
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5))
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5), Decl(input.js, 15, 32))
>defaultProps : Symbol(MyComponent2.defaultProps, Decl(input.js, 15, 32))

color: "red"
Expand All @@ -41,7 +41,7 @@ MyComponent2.defaultProps = {
*/
const check = MyComponent2;
>check : Symbol(check, Decl(input.js, 27, 5))
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5))
>MyComponent2 : Symbol(MyComponent2, Decl(input.js, 15, 5), Decl(input.js, 15, 32))

/**
*
Expand Down
Loading