Skip to content

Commit

Permalink
Merge branch 'master' into symbolic-declaration-files
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Jul 22, 2019
2 parents 550014d + 70b7bd5 commit eb4a036
Show file tree
Hide file tree
Showing 117 changed files with 11,687 additions and 11,414 deletions.
120 changes: 77 additions & 43 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5121,10 +5121,6 @@
"category": "Error",
"code": 18004
},
"Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '[\"constructor\"]()' to write a method.": {
"category": "Error",
"code": 18005
},
"Classes may not have a field named 'constructor'.": {
"category": "Error",
"code": 18006
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ namespace ts {
}
);
if (emitOnlyDtsFiles && declarationTransform.transformed[0].kind === SyntaxKind.SourceFile) {
const sourceFile = declarationTransform.transformed[0] as SourceFile;
// Improved narrowing in master/3.6 makes this cast unnecessary, triggering a lint rule.
// But at the same time, the LKG (3.5) necessitates it because it doesn’t narrow.
// Once the LKG is updated to 3.6, this comment, the cast to `SourceFile`, and the
// tslint directive can be all be removed.
const sourceFile = declarationTransform.transformed[0] as SourceFile; // tslint:disable-line
exportedModulesFromDeclarationEmit = sourceFile.exportedModulesFromDeclarationEmit;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4706,7 +4706,7 @@ namespace ts {
}
}

function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) {
export function getLeftmostExpression(node: Expression, stopAtCallExpressions: boolean) {
while (true) {
switch (node.kind) {
case SyntaxKind.PostfixUnaryExpression:
Expand Down
34 changes: 26 additions & 8 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5656,12 +5656,27 @@ namespace ts {
return finishNode(node);
}

function parseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration {
node.kind = SyntaxKind.Constructor;
parseExpected(SyntaxKind.ConstructorKeyword);
fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node);
node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected);
return finishNode(node);
function parseConstructorName() {
if (token() === SyntaxKind.ConstructorKeyword) {
return parseExpected(SyntaxKind.ConstructorKeyword);
}
if (token() === SyntaxKind.StringLiteral && lookAhead(nextToken) === SyntaxKind.OpenParenToken) {
return tryParse(() => {
const literalNode = parseLiteralNode();
return literalNode.text === "constructor" ? literalNode : undefined;
});
}
}

function tryParseConstructorDeclaration(node: ConstructorDeclaration): ConstructorDeclaration | undefined {
return tryParse(() => {
if (parseConstructorName()) {
node.kind = SyntaxKind.Constructor;
fillSignature(SyntaxKind.ColonToken, SignatureFlags.None, node);
node.body = parseFunctionBlockOrSemicolon(SignatureFlags.None, Diagnostics.or_expected);
return finishNode(node);
}
});
}

function parseMethodDeclaration(node: MethodDeclaration, asteriskToken: AsteriskToken, diagnosticMessage?: DiagnosticMessage): MethodDeclaration {
Expand Down Expand Up @@ -5867,8 +5882,11 @@ namespace ts {
return parseAccessorDeclaration(<AccessorDeclaration>node, SyntaxKind.SetAccessor);
}

if (token() === SyntaxKind.ConstructorKeyword) {
return parseConstructorDeclaration(<ConstructorDeclaration>node);
if (token() === SyntaxKind.ConstructorKeyword || token() === SyntaxKind.StringLiteral) {
const constructorDeclaration = tryParseConstructorDeclaration(<ConstructorDeclaration>node);
if (constructorDeclaration) {
return constructorDeclaration;
}
}

if (isIndexSignature()) {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ namespace ts {
"|=": SyntaxKind.BarEqualsToken,
"^=": SyntaxKind.CaretEqualsToken,
"@": SyntaxKind.AtToken,
"`": SyntaxKind.BacktickToken
});

/*
Expand Down Expand Up @@ -298,7 +299,6 @@ namespace ts {
}

const tokenStrings = makeReverseMap(textToToken);

export function tokenToString(t: SyntaxKind): string | undefined {
return tokenStrings[t];
}
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,7 @@ namespace ts {
}

export interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
kind: SyntaxKind.JsxAttributes;
parent: JsxOpeningLikeElement;
}

Expand Down Expand Up @@ -4767,7 +4768,7 @@ namespace ts {
UMD = 3,
System = 4,
ES2015 = 5,
ESNext = 6
ESNext = 99
}

export const enum JsxEmit {
Expand Down Expand Up @@ -4815,7 +4816,7 @@ namespace ts {
ES2018 = 5,
ES2019 = 6,
ES2020 = 7,
ESNext = 8,
ESNext = 99,
JSON = 100,
Latest = ESNext,
}
Expand Down
19 changes: 18 additions & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3173,6 +3173,23 @@ namespace ts {
return s.replace(escapedCharsRegExp, getReplacement);
}

/**
* Strip off existed single quotes or double quotes from a given string
*
* @return non-quoted string
*/
export function stripQuotes(name: string) {
const length = name.length;
if (length >= 2 && name.charCodeAt(0) === name.charCodeAt(length - 1) && startsWithQuote(name)) {
return name.substring(1, length - 1);
}
return name;
}

export function startsWithQuote(name: string): boolean {
return isSingleOrDoubleQuote(name.charCodeAt(0));
}

function getReplacement(c: string, offset: number, input: string) {
if (c.charCodeAt(0) === CharacterCodes.nullCharacter) {
const lookAhead = input.charCodeAt(offset + c.length);
Expand Down Expand Up @@ -7529,7 +7546,7 @@ namespace ts {
export function getDirectoryPath(path: Path): Path;
/**
* Returns the path except for its basename. Semantics align with NodeJS's `path.dirname`
* except that we support URLs as well.
* except that we support URL's as well.
*
* ```ts
* getDirectoryPath("/path/to/file.ext") === "/path/to"
Expand Down
Loading

0 comments on commit eb4a036

Please sign in to comment.