Propagate CheckFlags.Late through instantiateSymbol (#22749)

This commit is contained in:
Wesley Wigham 2018-03-29 13:42:26 -07:00 committed by GitHub
parent 411c59a8ef
commit 509a53fea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 113 additions and 1 deletions

View file

@ -8922,7 +8922,7 @@ namespace ts {
}
// Keep the flags from the symbol we're instantiating. Mark that is instantiated, and
// also transient so that we can just store data on it directly.
const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated);
const result = createSymbol(symbol.flags, symbol.escapedName, CheckFlags.Instantiated | (getCheckFlags(symbol) & CheckFlags.Late));
result.declarations = symbol.declarations;
result.parent = symbol.parent;
result.target = symbol;

View file

@ -0,0 +1,14 @@
tests/cases/compiler/file.ts(4,17): error TS4060: Return type of exported function has or is using private name 'IGNORE_EXTRA_VARIABLES'.
==== tests/cases/compiler/file.ts (1 errors) ====
const IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
//This is exported
export function ignoreExtraVariables<CtorT extends {new(...args:any[]):{}}> (ctor : CtorT) {
~~~~~~~~~~~~~~~~~~~~
!!! error TS4060: Return type of exported function has or is using private name 'IGNORE_EXTRA_VARIABLES'.
return class extends ctor {
[IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used
};
}

View file

@ -0,0 +1,40 @@
//// [file.ts]
const IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
//This is exported
export function ignoreExtraVariables<CtorT extends {new(...args:any[]):{}}> (ctor : CtorT) {
return class extends ctor {
[IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used
};
}
//// [file.js]
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
exports.__esModule = true;
var IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
//This is exported
function ignoreExtraVariables(ctor) {
return _a = /** @class */ (function (_super) {
__extends(class_1, _super);
function class_1() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this[_b] = true; //An unexported constant is used
return _this;
}
return class_1;
}(ctor)),
_b = IGNORE_EXTRA_VARIABLES,
_a;
var _b, _a;
}
exports.ignoreExtraVariables = ignoreExtraVariables;

View file

@ -0,0 +1,22 @@
=== tests/cases/compiler/file.ts ===
const IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
>IGNORE_EXTRA_VARIABLES : Symbol(IGNORE_EXTRA_VARIABLES, Decl(file.ts, 0, 5))
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
//This is exported
export function ignoreExtraVariables<CtorT extends {new(...args:any[]):{}}> (ctor : CtorT) {
>ignoreExtraVariables : Symbol(ignoreExtraVariables, Decl(file.ts, 0, 40))
>CtorT : Symbol(CtorT, Decl(file.ts, 3, 37))
>args : Symbol(args, Decl(file.ts, 3, 56))
>ctor : Symbol(ctor, Decl(file.ts, 3, 77))
>CtorT : Symbol(CtorT, Decl(file.ts, 3, 37))
return class extends ctor {
>ctor : Symbol(ctor, Decl(file.ts, 3, 77))
[IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used
>[IGNORE_EXTRA_VARIABLES] : Symbol((Anonymous class)[IGNORE_EXTRA_VARIABLES], Decl(file.ts, 4, 31))
>IGNORE_EXTRA_VARIABLES : Symbol(IGNORE_EXTRA_VARIABLES, Decl(file.ts, 0, 5))
};
}

View file

@ -0,0 +1,25 @@
=== tests/cases/compiler/file.ts ===
const IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
>IGNORE_EXTRA_VARIABLES : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor
//This is exported
export function ignoreExtraVariables<CtorT extends {new(...args:any[]):{}}> (ctor : CtorT) {
>ignoreExtraVariables : <CtorT extends new (...args: any[]) => {}>(ctor: CtorT) => { new (...args: any[]): (Anonymous class); prototype: ignoreExtraVariables<any>.(Anonymous class); } & CtorT
>CtorT : CtorT
>args : any[]
>ctor : CtorT
>CtorT : CtorT
return class extends ctor {
>class extends ctor { [IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used } : { new (...args: any[]): (Anonymous class); prototype: ignoreExtraVariables<any>.(Anonymous class); } & CtorT
>ctor : {}
[IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used
>[IGNORE_EXTRA_VARIABLES] : boolean
>IGNORE_EXTRA_VARIABLES : unique symbol
>true : true
};
}

View file

@ -0,0 +1,11 @@
// @declaration: true
// @lib: es6
// @filename: file.ts
const IGNORE_EXTRA_VARIABLES = Symbol(); //Notice how this is unexported
//This is exported
export function ignoreExtraVariables<CtorT extends {new(...args:any[]):{}}> (ctor : CtorT) {
return class extends ctor {
[IGNORE_EXTRA_VARIABLES] = true; //An unexported constant is used
};
}