Skip to content

Commit 2a30aaf

Browse files
committed
Merge branch 'master' into nominalInstanceof
2 parents 412f373 + 7985e66 commit 2a30aaf

File tree

201 files changed

+3283
-630
lines changed

Some content is hidden

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

201 files changed

+3283
-630
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ language: node_js
22

33
node_js:
44
- 'stable'
5+
- '8'
56
- '6'
6-
- '4'
77

88
sudo: false
99

Gulpfile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ const librarySourceMap = [
171171
// JavaScript + all host library
172172
{ target: "lib.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(hostsLibrarySources) },
173173
{ target: "lib.es6.d.ts", sources: ["header.d.ts", "es5.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
174-
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
175-
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
176-
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(es2015LibrarySources, hostsLibrarySources, "dom.iterable.d.ts") },
174+
{ target: "lib.es2016.full.d.ts", sources: ["header.d.ts", "es2016.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
175+
{ target: "lib.es2017.full.d.ts", sources: ["header.d.ts", "es2017.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
176+
{ target: "lib.esnext.full.d.ts", sources: ["header.d.ts", "esnext.d.ts"].concat(hostsLibrarySources, "dom.iterable.d.ts") },
177177
].concat(es2015LibrarySourceMap, es2016LibrarySourceMap, es2017LibrarySourceMap, esnextLibrarySourceMap);
178178

179179
const libraryTargets = librarySourceMap.map(function(f) {

netci.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import jobs.generation.Utilities;
55
def project = GithubProject
66
def branch = GithubBranchName
77

8-
def nodeVersions = ['stable', '6', '4']
8+
def nodeVersions = ['stable', '8', '6']
99

1010
nodeVersions.each { nodeVer ->
1111

scripts/generateLocalizedDiagnosticMessages.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ function main(): void {
6565
* There are three exceptions, zh-CN, zh-TW and pt-BR.
6666
*/
6767
function getPreferedLocaleName(localeName: string) {
68+
localeName = localeName.toLowerCase();
6869
switch (localeName) {
69-
case "zh-CN":
70-
case "zh-TW":
71-
case "pt-BR":
70+
case "zh-cn":
71+
case "zh-tw":
72+
case "pt-br":
7273
return localeName;
7374
default:
7475
return localeName.split("-")[0];

src/compiler/binder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ namespace ts {
192192
return bindSourceFile;
193193

194194
function bindInStrictMode(file: SourceFile, opts: CompilerOptions): boolean {
195-
if ((opts.alwaysStrict === undefined ? opts.strict : opts.alwaysStrict) && !file.isDeclarationFile) {
195+
if (getStrictOptionValue(opts, "alwaysStrict") && !file.isDeclarationFile) {
196196
// bind in strict mode source files with alwaysStrict option
197197
return true;
198198
}
@@ -3296,6 +3296,9 @@ namespace ts {
32963296
case SyntaxKind.JsxOpeningElement:
32973297
case SyntaxKind.JsxText:
32983298
case SyntaxKind.JsxClosingElement:
3299+
case SyntaxKind.JsxFragment:
3300+
case SyntaxKind.JsxOpeningFragment:
3301+
case SyntaxKind.JsxClosingFragment:
32993302
case SyntaxKind.JsxAttribute:
33003303
case SyntaxKind.JsxAttributes:
33013304
case SyntaxKind.JsxSpreadAttribute:

src/compiler/checker.ts

Lines changed: 83 additions & 52 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,13 @@ namespace ts {
11381138
reportInvalidOptionValue(option && option.type !== "number");
11391139
return Number((<NumericLiteral>valueExpression).text);
11401140

1141+
case SyntaxKind.PrefixUnaryExpression:
1142+
if ((<PrefixUnaryExpression>valueExpression).operator !== SyntaxKind.MinusToken || (<PrefixUnaryExpression>valueExpression).operand.kind !== SyntaxKind.NumericLiteral) {
1143+
break; // not valid JSON syntax
1144+
}
1145+
reportInvalidOptionValue(option && option.type !== "number");
1146+
return -Number((<NumericLiteral>(<PrefixUnaryExpression>valueExpression).operand).text);
1147+
11411148
case SyntaxKind.ObjectLiteralExpression:
11421149
reportInvalidOptionValue(option && option.type !== "object");
11431150
const objectLiteralExpression = <ObjectLiteralExpression>valueExpression;

src/compiler/core.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -985,32 +985,6 @@ namespace ts {
985985
return initial;
986986
}
987987

988-
export function reduceRight<T, U>(array: ReadonlyArray<T>, f: (memo: U, value: T, i: number) => U, initial: U, start?: number, count?: number): U;
989-
export function reduceRight<T>(array: ReadonlyArray<T>, f: (memo: T, value: T, i: number) => T): T;
990-
export function reduceRight<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T {
991-
if (array) {
992-
const size = array.length;
993-
if (size > 0) {
994-
let pos = start === undefined || start > size - 1 ? size - 1 : start;
995-
const end = count === undefined || pos - count < 0 ? 0 : pos - count;
996-
let result: T;
997-
if (arguments.length <= 2) {
998-
result = array[pos];
999-
pos--;
1000-
}
1001-
else {
1002-
result = initial;
1003-
}
1004-
while (pos >= end) {
1005-
result = f(result, array[pos], pos);
1006-
pos--;
1007-
}
1008-
return result;
1009-
}
1010-
}
1011-
return initial;
1012-
}
1013-
1014988
const hasOwnProperty = Object.prototype.hasOwnProperty;
1015989

1016990
/**
@@ -1710,6 +1684,12 @@ namespace ts {
17101684
return moduleResolution;
17111685
}
17121686

1687+
export type StrictOptionName = "noImplicitAny" | "noImplicitThis" | "strictNullChecks" | "strictFunctionTypes" | "alwaysStrict";
1688+
1689+
export function getStrictOptionValue(compilerOptions: CompilerOptions, flag: StrictOptionName): boolean {
1690+
return compilerOptions[flag] === undefined ? compilerOptions.strict : compilerOptions[flag];
1691+
}
1692+
17131693
export function hasZeroOrOneAsteriskCharacter(str: string): boolean {
17141694
let seenAsterisk = false;
17151695
for (let i = 0; i < str.length; i++) {

src/compiler/diagnosticMessages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3615,6 +3615,18 @@
36153615
"category": "Error",
36163616
"code": 17013
36173617
},
3618+
"JSX fragment has no corresponding closing tag.": {
3619+
"category": "Error",
3620+
"code": 17014
3621+
},
3622+
"Expected corresponding closing tag for JSX fragment.": {
3623+
"category": "Error",
3624+
"code": 17015
3625+
},
3626+
"JSX fragment is not supported when using --jsxFactory": {
3627+
"category": "Error",
3628+
"code":17016
3629+
},
36183630

36193631
"Circularity detected while resolving configuration: {0}": {
36203632
"category": "Error",

src/compiler/emitter.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,11 @@ namespace ts {
699699
case SyntaxKind.JsxText:
700700
return emitJsxText(<JsxText>node);
701701
case SyntaxKind.JsxOpeningElement:
702-
return emitJsxOpeningElement(<JsxOpeningElement>node);
702+
case SyntaxKind.JsxOpeningFragment:
703+
return emitJsxOpeningElementOrFragment(<JsxOpeningElement>node);
703704
case SyntaxKind.JsxClosingElement:
704-
return emitJsxClosingElement(<JsxClosingElement>node);
705+
case SyntaxKind.JsxClosingFragment:
706+
return emitJsxClosingElementOrFragment(<JsxClosingElement>node);
705707
case SyntaxKind.JsxAttribute:
706708
return emitJsxAttribute(<JsxAttribute>node);
707709
case SyntaxKind.JsxAttributes:
@@ -836,6 +838,8 @@ namespace ts {
836838
return emitJsxElement(<JsxElement>node);
837839
case SyntaxKind.JsxSelfClosingElement:
838840
return emitJsxSelfClosingElement(<JsxSelfClosingElement>node);
841+
case SyntaxKind.JsxFragment:
842+
return emitJsxFragment(<JsxFragment>node);
839843

840844
// Transformation nodes
841845
case SyntaxKind.PartiallyEmittedExpression:
@@ -2060,7 +2064,7 @@ namespace ts {
20602064

20612065
function emitJsxElement(node: JsxElement) {
20622066
emit(node.openingElement);
2063-
emitList(node, node.children, ListFormat.JsxElementChildren);
2067+
emitList(node, node.children, ListFormat.JsxElementOrFragmentChildren);
20642068
emit(node.closingElement);
20652069
}
20662070

@@ -2075,24 +2079,36 @@ namespace ts {
20752079
write("/>");
20762080
}
20772081

2078-
function emitJsxOpeningElement(node: JsxOpeningElement) {
2082+
function emitJsxFragment(node: JsxFragment) {
2083+
emit(node.openingFragment);
2084+
emitList(node, node.children, ListFormat.JsxElementOrFragmentChildren);
2085+
emit(node.closingFragment);
2086+
}
2087+
2088+
function emitJsxOpeningElementOrFragment(node: JsxOpeningElement | JsxOpeningFragment) {
20792089
write("<");
2080-
emitJsxTagName(node.tagName);
2081-
writeIfAny(node.attributes.properties, " ");
2082-
// We are checking here so we won't re-enter the emitting pipeline and emit extra sourcemap
2083-
if (node.attributes.properties && node.attributes.properties.length > 0) {
2084-
emit(node.attributes);
2090+
2091+
if (isJsxOpeningElement(node)) {
2092+
emitJsxTagName(node.tagName);
2093+
// We are checking here so we won't re-enter the emitting pipeline and emit extra sourcemap
2094+
if (node.attributes.properties && node.attributes.properties.length > 0) {
2095+
write(" ");
2096+
emit(node.attributes);
2097+
}
20852098
}
2099+
20862100
write(">");
20872101
}
20882102

20892103
function emitJsxText(node: JsxText) {
20902104
writer.writeLiteral(getTextOfNode(node, /*includeTrivia*/ true));
20912105
}
20922106

2093-
function emitJsxClosingElement(node: JsxClosingElement) {
2107+
function emitJsxClosingElementOrFragment(node: JsxClosingElement | JsxClosingFragment) {
20942108
write("</");
2095-
emitJsxTagName(node.tagName);
2109+
if (isJsxClosingElement(node)) {
2110+
emitJsxTagName(node.tagName);
2111+
}
20962112
write(">");
20972113
}
20982114

@@ -2611,12 +2627,6 @@ namespace ts {
26112627
writer.decreaseIndent();
26122628
}
26132629

2614-
function writeIfAny(nodes: NodeArray<Node>, text: string) {
2615-
if (some(nodes)) {
2616-
write(text);
2617-
}
2618-
}
2619-
26202630
function writeToken(token: SyntaxKind, pos: number, contextNode?: Node) {
26212631
return onEmitSourceMapOfToken
26222632
? onEmitSourceMapOfToken(contextNode, token, pos, writeTokenText)
@@ -3176,7 +3186,7 @@ namespace ts {
31763186
EnumMembers = CommaDelimited | Indented | MultiLine,
31773187
CaseBlockClauses = Indented | MultiLine,
31783188
NamedImportsOrExportsElements = CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | SingleLine | SpaceBetweenBraces,
3179-
JsxElementChildren = SingleLine | NoInterveningComments,
3189+
JsxElementOrFragmentChildren = SingleLine | NoInterveningComments,
31803190
JsxElementAttributes = SingleLine | SpaceBetweenSiblings | NoInterveningComments,
31813191
CaseOrDefaultClauseStatements = Indented | MultiLine | NoTrailingNewLine | OptionalIfEmpty,
31823192
HeritageClauseTypes = CommaDelimited | SpaceBetweenSiblings | SingleLine,

src/compiler/factory.ts

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ namespace ts {
19821982
node.decorators = asNodeArray(decorators);
19831983
node.modifiers = asNodeArray(modifiers);
19841984
node.isExportEquals = isExportEquals;
1985-
node.expression = expression;
1985+
node.expression = isExportEquals ? parenthesizeBinaryOperand(SyntaxKind.EqualsToken, expression, /*isLeftSideOfBinary*/ false, /*leftOperand*/ undefined) : parenthesizeDefaultExpression(expression);
19861986
return node;
19871987
}
19881988

@@ -2115,6 +2115,22 @@ namespace ts {
21152115
: node;
21162116
}
21172117

2118+
export function createJsxFragment(openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment) {
2119+
const node = <JsxFragment>createSynthesizedNode(SyntaxKind.JsxFragment);
2120+
node.openingFragment = openingFragment;
2121+
node.children = createNodeArray(children);
2122+
node.closingFragment = closingFragment;
2123+
return node;
2124+
}
2125+
2126+
export function updateJsxFragment(node: JsxFragment, openingFragment: JsxOpeningFragment, children: ReadonlyArray<JsxChild>, closingFragment: JsxClosingFragment) {
2127+
return node.openingFragment !== openingFragment
2128+
|| node.children !== children
2129+
|| node.closingFragment !== closingFragment
2130+
? updateNode(createJsxFragment(openingFragment, children, closingFragment), node)
2131+
: node;
2132+
}
2133+
21182134
export function createJsxAttribute(name: Identifier, initializer: StringLiteral | JsxExpression) {
21192135
const node = <JsxAttribute>createSynthesizedNode(SyntaxKind.JsxAttribute);
21202136
node.name = name;
@@ -2951,7 +2967,7 @@ namespace ts {
29512967
);
29522968
}
29532969

2954-
function createReactNamespace(reactNamespace: string, parent: JsxOpeningLikeElement) {
2970+
function createReactNamespace(reactNamespace: string, parent: JsxOpeningLikeElement | JsxOpeningFragment) {
29552971
// To ensure the emit resolver can properly resolve the namespace, we need to
29562972
// treat this identifier as if it were a source tree node by clearing the `Synthesized`
29572973
// flag and setting a parent node.
@@ -2963,7 +2979,7 @@ namespace ts {
29632979
return react;
29642980
}
29652981

2966-
function createJsxFactoryExpressionFromEntityName(jsxFactory: EntityName, parent: JsxOpeningLikeElement): Expression {
2982+
function createJsxFactoryExpressionFromEntityName(jsxFactory: EntityName, parent: JsxOpeningLikeElement | JsxOpeningFragment): Expression {
29672983
if (isQualifiedName(jsxFactory)) {
29682984
const left = createJsxFactoryExpressionFromEntityName(jsxFactory.left, parent);
29692985
const right = createIdentifier(idText(jsxFactory.right));
@@ -2975,7 +2991,7 @@ namespace ts {
29752991
}
29762992
}
29772993

2978-
function createJsxFactoryExpression(jsxFactoryEntity: EntityName, reactNamespace: string, parent: JsxOpeningLikeElement): Expression {
2994+
function createJsxFactoryExpression(jsxFactoryEntity: EntityName, reactNamespace: string, parent: JsxOpeningLikeElement | JsxOpeningFragment): Expression {
29792995
return jsxFactoryEntity ?
29802996
createJsxFactoryExpressionFromEntityName(jsxFactoryEntity, parent) :
29812997
createPropertyAccess(
@@ -3016,6 +3032,37 @@ namespace ts {
30163032
);
30173033
}
30183034

3035+
export function createExpressionForJsxFragment(jsxFactoryEntity: EntityName, reactNamespace: string, children: Expression[], parentElement: JsxOpeningFragment, location: TextRange): LeftHandSideExpression {
3036+
const tagName = createPropertyAccess(
3037+
createReactNamespace(reactNamespace, parentElement),
3038+
"Fragment"
3039+
);
3040+
3041+
const argumentsList = [<Expression>tagName];
3042+
argumentsList.push(createNull());
3043+
3044+
if (children && children.length > 0) {
3045+
if (children.length > 1) {
3046+
for (const child of children) {
3047+
child.startsOnNewLine = true;
3048+
argumentsList.push(child);
3049+
}
3050+
}
3051+
else {
3052+
argumentsList.push(children[0]);
3053+
}
3054+
}
3055+
3056+
return setTextRange(
3057+
createCall(
3058+
createJsxFactoryExpression(jsxFactoryEntity, reactNamespace, parentElement),
3059+
/*typeArguments*/ undefined,
3060+
argumentsList
3061+
),
3062+
location
3063+
);
3064+
}
3065+
30193066
// Helpers
30203067

30213068
export function getHelperName(name: string) {
@@ -3885,6 +3932,27 @@ namespace ts {
38853932
: e;
38863933
}
38873934

3935+
/**
3936+
* [Per the spec](https://tc39.github.io/ecma262/#prod-ExportDeclaration), `export default` accepts _AssigmentExpression_ but
3937+
* has a lookahead restriction for `function`, `async function`, and `class`.
3938+
*
3939+
* Basically, that means we need to parenthesize in the following cases:
3940+
*
3941+
* - BinaryExpression of CommaToken
3942+
* - CommaList (synthetic list of multiple comma expressions)
3943+
* - FunctionExpression
3944+
* - ClassExpression
3945+
*/
3946+
export function parenthesizeDefaultExpression(e: Expression) {
3947+
const check = skipPartiallyEmittedExpressions(e);
3948+
return (check.kind === SyntaxKind.ClassExpression ||
3949+
check.kind === SyntaxKind.FunctionExpression ||
3950+
check.kind === SyntaxKind.CommaListExpression ||
3951+
isBinaryExpression(check) && check.operatorToken.kind === SyntaxKind.CommaToken)
3952+
? createParen(e)
3953+
: e;
3954+
}
3955+
38883956
/**
38893957
* Wraps an expression in parentheses if it is needed in order to use the expression
38903958
* as the expression of a NewExpression node.

0 commit comments

Comments
 (0)