Skip to content

Commit ad9e9b7

Browse files
committed
Merge remote-tracking branch 'origin/master' into release-2.3
2 parents 4318c94 + 8324244 commit ad9e9b7

File tree

268 files changed

+5290
-2247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

268 files changed

+5290
-2247
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ branches:
1818
- master
1919
- release-2.1
2020
- release-2.2
21+
- release-2.3
2122

2223
install:
2324
- npm uninstall typescript
2425
- npm uninstall tslint
2526
- npm install
26-
- npm update
2727

2828
cache:
2929
directories:

Gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
4141
boolean: ["debug", "inspect", "light", "colors", "lint", "soft"],
4242
string: ["browser", "tests", "host", "reporter", "stackTraceLimit"],
4343
alias: {
44+
b: "browser",
4445
d: "debug",
4546
t: "tests",
4647
test: "tests",

src/compiler/binder.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ namespace ts {
22982298

22992299
function isNameOfExportsOrModuleExportsAliasDeclaration(node: Node) {
23002300
if (node.kind === SyntaxKind.Identifier) {
2301-
const symbol = container.locals.get((<Identifier>node).text);
2301+
const symbol = lookupSymbolForName((<Identifier>node).text);
23022302
if (symbol && symbol.valueDeclaration && symbol.valueDeclaration.kind === SyntaxKind.VariableDeclaration) {
23032303
const declaration = symbol.valueDeclaration as VariableDeclaration;
23042304
if (declaration.initializer) {
@@ -2400,8 +2400,12 @@ namespace ts {
24002400
}
24012401
}
24022402

2403+
function lookupSymbolForName(name: string) {
2404+
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || container.locals.get(name);
2405+
}
2406+
24032407
function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
2404-
let targetSymbol = container.locals.get(functionName);
2408+
let targetSymbol = lookupSymbolForName(functionName);
24052409

24062410
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
24072411
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;

src/compiler/checker.ts

Lines changed: 72 additions & 43 deletions
Large diffs are not rendered by default.

src/compiler/core.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,12 @@ namespace ts {
887887
}
888888

889889
/** Shims `Array.from`. */
890-
export function arrayFrom<T>(iterator: Iterator<T>): T[] {
891-
const result: T[] = [];
890+
export function arrayFrom<T, U>(iterator: Iterator<T>, map: (t: T) => U): U[];
891+
export function arrayFrom<T>(iterator: Iterator<T>): T[];
892+
export function arrayFrom(iterator: Iterator<any>, map?: (t: any) => any): any[] {
893+
const result: any[] = [];
892894
for (let { value, done } = iterator.next(); !done; { value, done } = iterator.next()) {
893-
result.push(value);
895+
result.push(map ? map(value) : value);
894896
}
895897
return result;
896898
}

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,14 @@
20992099
"category": "Error",
21002100
"code": 2707
21012101
},
2102+
"Cannot use namespace '{0}' as a value.": {
2103+
"category": "Error",
2104+
"code": 2708
2105+
},
2106+
"Cannot use namespace '{0}' as a type.": {
2107+
"category": "Error",
2108+
"code": 2709
2109+
},
21022110

21032111
"Import declaration '{0}' is using private name '{1}'.": {
21042112
"category": "Error",

src/compiler/factory.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,15 +3058,26 @@ namespace ts {
30583058
* @param ensureUseStrict: boolean determining whether the function need to add prologue-directives
30593059
* @param visitor: Optional callback used to visit any custom prologue directives.
30603060
*/
3061-
export function addPrologueDirectives(target: Statement[], source: Statement[], ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
3061+
export function addPrologue(target: Statement[], source: Statement[], ensureUseStrict?: boolean, visitor?: (node: Node) => VisitResult<Node>): number {
3062+
const offset = addStandardPrologue(target, source, ensureUseStrict);
3063+
return addCustomPrologue(target, source, offset, visitor);
3064+
}
3065+
3066+
/**
3067+
* Add just the standard (string-expression) prologue-directives into target statement-array.
3068+
* The function needs to be called during each transformation step.
3069+
* This function needs to be called whenever we transform the statement
3070+
* list of a source file, namespace, or function-like body.
3071+
*/
3072+
export function addStandardPrologue(target: Statement[], source: Statement[], ensureUseStrict?: boolean): number {
30623073
Debug.assert(target.length === 0, "Prologue directives should be at the first statement in the target statements array");
30633074
let foundUseStrict = false;
30643075
let statementOffset = 0;
30653076
const numStatements = source.length;
30663077
while (statementOffset < numStatements) {
30673078
const statement = source[statementOffset];
30683079
if (isPrologueDirective(statement)) {
3069-
if (isUseStrictPrologue(statement as ExpressionStatement)) {
3080+
if (isUseStrictPrologue(statement)) {
30703081
foundUseStrict = true;
30713082
}
30723083
target.push(statement);
@@ -3079,6 +3090,17 @@ namespace ts {
30793090
if (ensureUseStrict && !foundUseStrict) {
30803091
target.push(startOnNewLine(createStatement(createLiteral("use strict"))));
30813092
}
3093+
return statementOffset;
3094+
}
3095+
3096+
/**
3097+
* Add just the custom prologue-directives into target statement-array.
3098+
* The function needs to be called during each transformation step.
3099+
* This function needs to be called whenever we transform the statement
3100+
* list of a source file, namespace, or function-like body.
3101+
*/
3102+
export function addCustomPrologue(target: Statement[], source: Statement[], statementOffset: number, visitor?: (node: Node) => VisitResult<Node>): number {
3103+
const numStatements = source.length;
30823104
while (statementOffset < numStatements) {
30833105
const statement = source[statementOffset];
30843106
if (getEmitFlags(statement) & EmitFlags.CustomPrologue) {

src/compiler/parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ namespace ts {
458458
return Parser.parseIsolatedEntityName(text, languageVersion);
459459
}
460460

461+
// See also `isExternalOrCommonJsModule` in utilities.ts
461462
export function isExternalModule(file: SourceFile): boolean {
462463
return file.externalModuleIndicator !== undefined;
463464
}

src/compiler/transformers/es2015.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,9 @@ namespace ts {
515515
const ancestorFacts = enterSubtree(HierarchyFacts.SourceFileExcludes, HierarchyFacts.SourceFileIncludes);
516516
const statements: Statement[] = [];
517517
startLexicalEnvironment();
518-
const statementOffset = addPrologueDirectives(statements, node.statements, /*ensureUseStrict*/ false, visitor);
518+
let statementOffset = addStandardPrologue(statements, node.statements, /*ensureUseStrict*/ false);
519519
addCaptureThisForNodeIfNeeded(statements, node);
520+
statementOffset = addCustomPrologue(statements, node.statements, statementOffset, visitor);
520521
addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
521522
addRange(statements, endLexicalEnvironment());
522523
exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None);
@@ -924,13 +925,16 @@ namespace ts {
924925
statementOffset = 0;
925926
}
926927
else if (constructor) {
927-
// Otherwise, try to emit all potential prologue directives first.
928-
statementOffset = addPrologueDirectives(statements, constructor.body.statements, /*ensureUseStrict*/ false, visitor);
928+
statementOffset = addStandardPrologue(statements, constructor.body.statements, /*ensureUseStrict*/ false);
929929
}
930930

931931
if (constructor) {
932932
addDefaultValueAssignmentsIfNeeded(statements, constructor);
933933
addRestParameterIfNeeded(statements, constructor, hasSynthesizedSuper);
934+
if (!hasSynthesizedSuper) {
935+
// If no super call has been synthesized, emit custom prologue directives.
936+
statementOffset = addCustomPrologue(statements, constructor.body.statements, statementOffset, visitor);
937+
}
934938
Debug.assert(statementOffset >= 0, "statementOffset not initialized correctly!");
935939

936940
}
@@ -1821,8 +1825,8 @@ namespace ts {
18211825
resumeLexicalEnvironment();
18221826
if (isBlock(body)) {
18231827
// ensureUseStrict is false because no new prologue-directive should be added.
1824-
// addPrologueDirectives will simply put already-existing directives at the beginning of the target statement-array
1825-
statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor);
1828+
// addStandardPrologue will put already-existing directives at the beginning of the target statement-array
1829+
statementOffset = addStandardPrologue(statements, body.statements, /*ensureUseStrict*/ false);
18261830
}
18271831

18281832
addCaptureThisForNodeIfNeeded(statements, node);
@@ -1835,6 +1839,9 @@ namespace ts {
18351839
}
18361840

18371841
if (isBlock(body)) {
1842+
// addCustomPrologue puts already-existing directives at the beginning of the target statement-array
1843+
statementOffset = addCustomPrologue(statements, body.statements, statementOffset, visitor);
1844+
18381845
statementsLocation = body.statements;
18391846
addRange(statements, visitNodes(body.statements, visitor, isStatement, statementOffset));
18401847

src/compiler/transformers/es2017.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ namespace ts {
222222

223223
if (!isArrowFunction) {
224224
const statements: Statement[] = [];
225-
const statementOffset = addPrologueDirectives(statements, (<Block>node.body).statements, /*ensureUseStrict*/ false, visitor);
225+
const statementOffset = addPrologue(statements, (<Block>node.body).statements, /*ensureUseStrict*/ false, visitor);
226226
statements.push(
227227
createReturn(
228228
createAwaiterHelper(

0 commit comments

Comments
 (0)