Skip to content

Commit 4eba27b

Browse files
committed
Merge branch 'master' into watchOptions
2 parents a74e54e + 5887169 commit 4eba27b

13 files changed

+157
-28
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ scripts/word2md.js
3939
scripts/buildProtocol.js
4040
scripts/ior.js
4141
scripts/authors.js
42-
scripts/configureNightly.js
42+
scripts/configurePrerelease.js
4343
scripts/processDiagnosticMessages.d.ts
4444
scripts/processDiagnosticMessages.js
4545
scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js

Jakefile.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -556,16 +556,16 @@ desc("Generates a diagnostic file in TypeScript based on an input JSON file");
556556
task("generate-diagnostics", [diagnosticInfoMapTs]);
557557

558558
// Publish nightly
559-
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
560-
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
559+
var configurePrereleaseJs = path.join(scriptsDirectory, "configurePrerelease.js");
560+
var configurePrereleaseTs = path.join(scriptsDirectory, "configurePrerelease.ts");
561561
var packageJson = "package.json";
562562
var versionFile = path.join(compilerDirectory, "core.ts");
563563

564-
file(configureNightlyTs);
564+
file(configurePrereleaseTs);
565565

566-
compileFile(/*outfile*/configureNightlyJs,
567-
/*sources*/[configureNightlyTs],
568-
/*prereqs*/[configureNightlyTs],
566+
compileFile(/*outfile*/configurePrereleaseJs,
567+
/*sources*/[configurePrereleaseTs],
568+
/*prereqs*/[configurePrereleaseTs],
569569
/*prefixes*/[],
570570
/*useBuiltCompiler*/ false,
571571
{ noOutFile: false, generateDeclarations: false, keepComments: false, noResolve: false, stripInternal: false });
@@ -574,8 +574,8 @@ task("setDebugMode", function () {
574574
useDebugMode = true;
575575
});
576576

577-
task("configure-nightly", [configureNightlyJs], function () {
578-
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + versionFile;
577+
task("configure-nightly", [configurePrereleaseJs], function () {
578+
var cmd = host + " " + configurePrereleaseJs + " dev " + packageJson + " " + versionFile;
579579
console.log(cmd);
580580
exec(cmd);
581581
}, { async: true });
@@ -587,6 +587,19 @@ task("publish-nightly", ["configure-nightly", "LKG", "clean", "setDebugMode", "r
587587
exec(cmd);
588588
});
589589

590+
task("configure-insiders", [configurePrereleaseJs], function () {
591+
var cmd = host + " " + configurePrereleaseJs + " insiders " + packageJson + " " + versionFile;
592+
console.log(cmd);
593+
exec(cmd);
594+
}, { async: true });
595+
596+
desc("Configure, build, test, and publish the insiders release.");
597+
task("publish-insiders", ["configure-nightly", "LKG", "clean", "setDebugMode", "runtests-parallel"], function () {
598+
var cmd = "npm publish --tag insiders";
599+
console.log(cmd);
600+
exec(cmd);
601+
});
602+
590603
var importDefinitelyTypedTestsDirectory = path.join(scriptsDirectory, "importDefinitelyTypedTests");
591604
var importDefinitelyTypedTestsJs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.js");
592605
var importDefinitelyTypedTestsTs = path.join(importDefinitelyTypedTestsDirectory, "importDefinitelyTypedTests.ts");

scripts/configureNightly.ts renamed to scripts/configurePrerelease.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,39 @@ interface PackageJson {
1111

1212
function main(): void {
1313
const sys = ts.sys;
14-
if (sys.args.length < 2) {
14+
if (sys.args.length < 3) {
1515
sys.write("Usage:" + sys.newLine)
16-
sys.write("\tnode configureNightly.js <package.json location> <file containing version>" + sys.newLine);
16+
sys.write("\tnode configureNightly.js <dev|insiders> <package.json location> <file containing version>" + sys.newLine);
1717
return;
1818
}
1919

20+
const tag = sys.args[0];
21+
if (tag !== "dev" && tag !== "insiders") {
22+
throw new Error(`Unexpected tag name '${tag}'.`);
23+
}
24+
2025
// Acquire the version from the package.json file and modify it appropriately.
21-
const packageJsonFilePath = ts.normalizePath(sys.args[0]);
26+
const packageJsonFilePath = ts.normalizePath(sys.args[1]);
2227
const packageJsonValue: PackageJson = JSON.parse(sys.readFile(packageJsonFilePath));
2328

2429
const { majorMinor, patch } = parsePackageJsonVersion(packageJsonValue.version);
25-
const nightlyPatch = getNightlyPatch(patch);
30+
const prereleasePatch = getPrereleasePatch(tag, patch);
2631

2732
// Acquire and modify the source file that exposes the version string.
28-
const tsFilePath = ts.normalizePath(sys.args[1]);
33+
const tsFilePath = ts.normalizePath(sys.args[2]);
2934
const tsFileContents = ts.sys.readFile(tsFilePath);
30-
const modifiedTsFileContents = updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, nightlyPatch);
35+
const modifiedTsFileContents = updateTsFile(tsFilePath, tsFileContents, majorMinor, patch, prereleasePatch);
3136

3237
// Ensure we are actually changing something - the user probably wants to know that the update failed.
3338
if (tsFileContents === modifiedTsFileContents) {
34-
let err = `\n '${tsFilePath}' was not updated while configuring for a nightly publish.\n `;
39+
let err = `\n '${tsFilePath}' was not updated while configuring for a prerelease publish for '${tag}'.\n `;
3540
err += `Ensure that you have not already run this script; otherwise, erase your changes using 'git checkout -- "${tsFilePath}"'.`;
36-
throw err + "\n";
41+
throw new Error(err + "\n");
3742
}
3843

3944
// Finally write the changes to disk.
4045
// Modify the package.json structure
41-
packageJsonValue.version = `${majorMinor}.${nightlyPatch}`;
46+
packageJsonValue.version = `${majorMinor}.${prereleasePatch}`;
4247
sys.writeFile(packageJsonFilePath, JSON.stringify(packageJsonValue, /*replacer:*/ undefined, /*space:*/ 4))
4348
sys.writeFile(tsFilePath, modifiedTsFileContents);
4449
}
@@ -69,15 +74,15 @@ function parsePackageJsonVersion(versionString: string): { majorMinor: string, p
6974
}
7075

7176
/** e.g. 0-dev.20170707 */
72-
function getNightlyPatch(plainPatch: string): string {
77+
function getPrereleasePatch(tag: string, plainPatch: string): string {
7378
// We're going to append a representation of the current time at the end of the current version.
7479
// String.prototype.toISOString() returns a 24-character string formatted as 'YYYY-MM-DDTHH:mm:ss.sssZ',
7580
// but we'd prefer to just remove separators and limit ourselves to YYYYMMDD.
7681
// UTC time will always be implicit here.
7782
const now = new Date();
7883
const timeStr = now.toISOString().replace(/:|T|\.|-/g, "").slice(0, 8);
7984

80-
return `${plainPatch}-dev.${timeStr}`;
85+
return `${plainPatch}-${tag}.${timeStr}`;
8186
}
8287

8388
main();

src/compiler/checker.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -5995,7 +5995,9 @@ namespace ts {
59955995
for (const memberType of types) {
59965996
for (const { escapedName } of getAugmentedPropertiesOfType(memberType)) {
59975997
if (!props.has(escapedName)) {
5998-
props.set(escapedName, createUnionOrIntersectionProperty(unionType as UnionType, escapedName));
5998+
const prop = createUnionOrIntersectionProperty(unionType as UnionType, escapedName);
5999+
// May be undefined if the property is private
6000+
if (prop) props.set(escapedName, prop);
59996001
}
60006002
}
60016003
}
@@ -6177,7 +6179,7 @@ namespace ts {
61776179
t;
61786180
}
61796181

6180-
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol {
6182+
function createUnionOrIntersectionProperty(containingType: UnionOrIntersectionType, name: __String): Symbol | undefined {
61816183
let props: Symbol[];
61826184
const isUnion = containingType.flags & TypeFlags.Union;
61836185
const excludeModifiers = isUnion ? ModifierFlags.NonPublicAccessibilityModifier : 0;

src/compiler/utilities.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4704,7 +4704,7 @@ namespace ts {
47044704
}
47054705

47064706
export function isTypeOfExpression(node: Node): node is TypeOfExpression {
4707-
return node.kind === SyntaxKind.AwaitExpression;
4707+
return node.kind === SyntaxKind.TypeOfExpression;
47084708
}
47094709

47104710
export function isVoidExpression(node: Node): node is VoidExpression {

src/harness/externalCompileRunner.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ function removeExpectedErrors(errors: string, cwd: string): string {
131131
function isUnexpectedError(cwd: string) {
132132
return (error: string[]) => {
133133
ts.Debug.assertGreaterThanOrEqual(error.length, 1);
134-
const match = error[0].match(/(.+\.ts)\((\d+),\d+\): error TS/);
134+
const match = error[0].match(/(.+\.tsx?)\((\d+),\d+\): error TS/);
135135
if (!match) {
136136
return true;
137137
}
138138
const [, errorFile, lineNumberString] = match;
139139
const lines = fs.readFileSync(path.join(cwd, errorFile), { encoding: "utf8" }).split("\n");
140-
const lineNumber = parseInt(lineNumberString);
140+
const lineNumber = parseInt(lineNumberString) - 1;
141141
ts.Debug.assertGreaterThanOrEqual(lineNumber, 0);
142142
ts.Debug.assertLessThan(lineNumber, lines.length);
143143
const previousLine = lineNumber - 1 > 0 ? lines[lineNumber - 1] : "";

src/services/completions.ts

+43
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace ts.Completions {
2020
None,
2121
ClassElementKeywords, // Keywords at class keyword
2222
ConstructorParameterKeywords, // Keywords at constructor parameter
23+
FunctionLikeBodyKeywords // Keywords at function like body
2324
}
2425

2526
export function getCompletionsAtPosition(
@@ -1060,6 +1061,10 @@ namespace ts.Completions {
10601061
return true;
10611062
}
10621063

1064+
if (tryGetFunctionLikeBodyCompletionContainer(contextToken)) {
1065+
keywordFilters = KeywordCompletionFilters.FunctionLikeBodyKeywords;
1066+
}
1067+
10631068
if (classLikeContainer = tryGetClassLikeCompletionContainer(contextToken)) {
10641069
// cursor inside class declaration
10651070
getGetClassLikeCompletionSymbols(classLikeContainer);
@@ -1688,6 +1693,22 @@ namespace ts.Completions {
16881693
return undefined;
16891694
}
16901695

1696+
function tryGetFunctionLikeBodyCompletionContainer(contextToken: Node): FunctionLikeDeclaration {
1697+
if (contextToken) {
1698+
let prev: Node;
1699+
const container = findAncestor(contextToken.parent, (node: Node) => {
1700+
if (isClassLike(node)) {
1701+
return "quit";
1702+
}
1703+
if (isFunctionLikeDeclaration(node) && prev === node.body) {
1704+
return true;
1705+
}
1706+
prev = node;
1707+
});
1708+
return container && container as FunctionLikeDeclaration;
1709+
}
1710+
}
1711+
16911712
function tryGetContainingJsxElement(contextToken: Node): JsxOpeningLikeElement {
16921713
if (contextToken) {
16931714
const parent = contextToken.parent;
@@ -2126,6 +2147,8 @@ namespace ts.Completions {
21262147
return getFilteredKeywordCompletions(isClassMemberCompletionKeywordText);
21272148
case KeywordCompletionFilters.ConstructorParameterKeywords:
21282149
return getFilteredKeywordCompletions(isConstructorParameterCompletionKeywordText);
2150+
case KeywordCompletionFilters.FunctionLikeBodyKeywords:
2151+
return getFilteredKeywordCompletions(isFunctionLikeBodyCompletionKeywordText);
21292152
default:
21302153
Debug.assertNever(keywordFilter);
21312154
}
@@ -2188,6 +2211,26 @@ namespace ts.Completions {
21882211
return isConstructorParameterCompletionKeyword(stringToToken(text));
21892212
}
21902213

2214+
function isFunctionLikeBodyCompletionKeyword(kind: SyntaxKind) {
2215+
switch (kind) {
2216+
case SyntaxKind.PublicKeyword:
2217+
case SyntaxKind.PrivateKeyword:
2218+
case SyntaxKind.ProtectedKeyword:
2219+
case SyntaxKind.ReadonlyKeyword:
2220+
case SyntaxKind.ConstructorKeyword:
2221+
case SyntaxKind.StaticKeyword:
2222+
case SyntaxKind.AbstractKeyword:
2223+
case SyntaxKind.GetKeyword:
2224+
case SyntaxKind.SetKeyword:
2225+
return false;
2226+
}
2227+
return true;
2228+
}
2229+
2230+
function isFunctionLikeBodyCompletionKeywordText(text: string) {
2231+
return isFunctionLikeBodyCompletionKeyword(stringToToken(text));
2232+
}
2233+
21912234
function isEqualityOperatorKind(kind: ts.SyntaxKind): kind is EqualityOperator {
21922235
switch (kind) {
21932236
case ts.SyntaxKind.EqualsEqualsEqualsToken:

src/services/formatting/rules.ts

+3
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ namespace ts.formatting {
321321
rule("NoSpaceAfterCloseBracket", SyntaxKind.CloseBracketToken, anyToken, [isNonJsxSameLineTokenContext, isNotBeforeBlockInFunctionDeclarationContext], RuleAction.Delete),
322322
rule("SpaceAfterSemicolon", SyntaxKind.SemicolonToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
323323

324+
// Remove extra space between for and await
325+
rule("SpaceBetweenForAndAwaitKeyword", SyntaxKind.ForKeyword, SyntaxKind.AwaitKeyword, [isNonJsxSameLineTokenContext], RuleAction.Space),
326+
324327
// Add a space between statements. All keywords except (do,else,case) has open/close parens after them.
325328
// So, we have a rule to add a space for [),Any], [do,Any], [else,Any], and [case,Any]
326329
rule(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
//// class Foo {
4+
//// bar () {
5+
//// /*1*/
6+
//// class Foo1 {
7+
//// bar1 () {
8+
//// /*2*/
9+
//// }
10+
//// /*3*/
11+
//// }
12+
//// }
13+
//// /*4*/
14+
//// }
15+
16+
17+
goTo.marker("1");
18+
verify.not.completionListContains("public", "public", /*documentation*/ undefined, "keyword");
19+
verify.not.completionListContains("private", "private", /*documentation*/ undefined, "keyword");
20+
verify.not.completionListContains("protected", "protected", /*documentation*/ undefined, "keyword");
21+
verify.not.completionListContains("constructor", "constructor", /*documentation*/ undefined, "keyword");
22+
verify.not.completionListContains("readonly", "readonly", /*documentation*/ undefined, "keyword");
23+
verify.not.completionListContains("static", "static", /*documentation*/ undefined, "keyword");
24+
verify.not.completionListContains("abstract", "abstract", /*documentation*/ undefined, "keyword");
25+
verify.not.completionListContains("get", "get", /*documentation*/ undefined, "keyword");
26+
verify.not.completionListContains("set", "set", /*documentation*/ undefined, "keyword");
27+
28+
goTo.marker("2");
29+
verify.not.completionListContains("public", "public", /*documentation*/ undefined, "keyword");
30+
verify.not.completionListContains("private", "private", /*documentation*/ undefined, "keyword");
31+
verify.not.completionListContains("protected", "protected", /*documentation*/ undefined, "keyword");
32+
verify.not.completionListContains("constructor", "constructor", /*documentation*/ undefined, "keyword");
33+
verify.not.completionListContains("readonly", "readonly", /*documentation*/ undefined, "keyword");
34+
verify.not.completionListContains("static", "static", /*documentation*/ undefined, "keyword");
35+
verify.not.completionListContains("abstract", "abstract", /*documentation*/ undefined, "keyword");
36+
verify.not.completionListContains("get", "get", /*documentation*/ undefined, "keyword");
37+
verify.not.completionListContains("set", "set", /*documentation*/ undefined, "keyword");
38+
39+
goTo.marker("3");
40+
verify.completionListContainsClassElementKeywords();
41+
42+
goTo.marker("4");
43+
verify.completionListContainsClassElementKeywords();

tests/cases/fourslash/completionInJSDocFunctionNew.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
////var f = function () { return new/**/; }
77

88
goTo.marker();
9-
verify.completionListCount(116);
9+
verify.completionListCount(107);
1010
verify.completionListContains('new');

tests/cases/fourslash/completionInJSDocFunctionThis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
////var f = function (s) { return this/**/; }
66

77
goTo.marker();
8-
verify.completionListCount(117);
8+
verify.completionListCount(108);
99
verify.completionListContains('this')

tests/cases/fourslash/completionsUnion.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
////interface I { x: number; }
44
////interface Many<T> extends ReadonlyArray<T> { extra: number; }
5-
////const x: I | I[] | Many<string> = { /**/ };
5+
////class C { private priv: number; }
6+
////const x: I | I[] | Many<string> | C = { /**/ };
67

78
// We specifically filter out any array-like types.
9+
// Private members will be excluded by `createUnionOrIntersectionProperty`.
810
verify.completionsAt("", ["x"]);
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
////async function f() {
4+
//// for await (const x of g()) {
5+
//// console.log(x);
6+
//// }
7+
////}
8+
9+
10+
format.document();
11+
12+
verify.currentFileContentIs(
13+
`async function f() {
14+
for await (const x of g()) {
15+
console.log(x);
16+
}
17+
}`
18+
);

0 commit comments

Comments
 (0)