diff --git a/scripts/errorCheck.ts b/scripts/errorCheck.ts index 77892cb8f0c..36489c5f312 100644 --- a/scripts/errorCheck.ts +++ b/scripts/errorCheck.ts @@ -4,84 +4,84 @@ let async = require('async'); let glob = require('glob'); fs.readFile('src/compiler/diagnosticMessages.json', 'utf-8', (err, data) => { - if (err) { - throw err; - } - - let messages = JSON.parse(data); - let keys = Object.keys(messages); - console.log('Loaded ' + keys.length + ' errors'); + if (err) { + throw err; + } - for (let k of keys) { - messages[k]['seen'] = false; - } + let messages = JSON.parse(data); + let keys = Object.keys(messages); + console.log('Loaded ' + keys.length + ' errors'); - let errRegex = /\(\d+,\d+\): error TS([^:]+):/g; + for (let k of keys) { + messages[k]['seen'] = false; + } - let baseDir = 'tests/baselines/reference/'; - fs.readdir(baseDir, (err, files) => { - files = files.filter(f => f.indexOf('.errors.txt') > 0); - let tasks: Array<(callback: () => void) => void> = []; - files.forEach(f => tasks.push(done => { - fs.readFile(baseDir + f, 'utf-8', (err, baseline) => { - if (err) throw err; + let errRegex = /\(\d+,\d+\): error TS([^:]+):/g; - let g: string[]; - while (g = errRegex.exec(baseline)) { - var errCode = +g[1]; - let msg = keys.filter(k => messages[k].code === errCode)[0]; - messages[msg]['seen'] = true; - } + let baseDir = 'tests/baselines/reference/'; + fs.readdir(baseDir, (err, files) => { + files = files.filter(f => f.indexOf('.errors.txt') > 0); + let tasks: Array<(callback: () => void) => void> = []; + files.forEach(f => tasks.push(done => { + fs.readFile(baseDir + f, 'utf-8', (err, baseline) => { + if (err) throw err; - done(); - }); - })); + let g: string[]; + while (g = errRegex.exec(baseline)) { + var errCode = +g[1]; + let msg = keys.filter(k => messages[k].code === errCode)[0]; + messages[msg]['seen'] = true; + } - async.parallelLimit(tasks, 25, done => { - console.log('== List of errors not present in baselines =='); - let count = 0; - for (let k of keys) { - if (messages[k]['seen'] !== true) { - console.log(k); - count++; - } - } - console.log(count + ' of ' + keys.length + ' errors are not in baselines'); - }); - }); + done(); + }); + })); + + async.parallelLimit(tasks, 25, done => { + console.log('== List of errors not present in baselines =='); + let count = 0; + for (let k of keys) { + if (messages[k]['seen'] !== true) { + console.log(k); + count++; + } + } + console.log(count + ' of ' + keys.length + ' errors are not in baselines'); + }); + }); }); fs.readFile('src/compiler/diagnosticInformationMap.generated.ts', 'utf-8', (err, data) => { - let errorRegexp = /\s(\w+): \{ code/g; - let errorNames: string[] = []; - let errMatch: string[]; - while (errMatch = errorRegexp.exec(data)) { - errorNames.push(errMatch[1]); - } + let errorRegexp = /\s(\w+): \{ code/g; + let errorNames: string[] = []; + let errMatch: string[]; + while (errMatch = errorRegexp.exec(data)) { + errorNames.push(errMatch[1]); + } - let allSrc: string = ''; - glob('./src/**/*.ts', {}, (err, files) => { - console.log('Reading ' + files.length + ' source files'); - for(let file of files) { - if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) { - continue; - } + let allSrc: string = ''; + glob('./src/**/*.ts', {}, (err, files) => { + console.log('Reading ' + files.length + ' source files'); + for (let file of files) { + if (file.indexOf('diagnosticInformationMap.generated.ts') > 0) { + continue; + } - let src = fs.readFileSync(file, 'utf-8'); - allSrc = allSrc + src; - } + let src = fs.readFileSync(file, 'utf-8'); + allSrc = allSrc + src; + } - console.log('Consumed ' + allSrc.length + ' characters of source'); + console.log('Consumed ' + allSrc.length + ' characters of source'); - let count = 0; - console.log('== List of errors not used in source ==') - for(let errName of errorNames) { - if (allSrc.indexOf(errName) < 0) { - console.log(errName); - count++; - } - } - console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); - }); + let count = 0; + console.log('== List of errors not used in source ==') + for (let errName of errorNames) { + if (allSrc.indexOf(errName) < 0) { + console.log(errName); + count++; + } + } + console.log(count + ' of ' + errorNames.length + ' errors are not used in source'); + }); }); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ec4c777852b..823349eda91 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -764,8 +764,8 @@ namespace ts { } Node.prototype = { kind: kind, - pos: 0, - end: 0, + pos: -1, + end: -1, flags: 0, parent: undefined, }; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c257f6c702e..f2f39b7495c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1979,8 +1979,8 @@ namespace ts { function parseParameter(): ParameterDeclaration { let node = createNode(SyntaxKind.Parameter); node.decorators = parseDecorators(); - node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); setModifiers(node, parseModifiers()); + node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f48e5306dce..e66e1925519 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -144,7 +144,7 @@ namespace ts { return true; } - return node.pos === node.end && node.kind !== SyntaxKind.EndOfFileToken; + return node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind.EndOfFileToken; } export function nodeIsPresent(node: Node) { @@ -1428,8 +1428,6 @@ namespace ts { export function createSynthesizedNode(kind: SyntaxKind, startsOnNewLine?: boolean): Node { let node = createNode(kind); - node.pos = -1; - node.end = -1; node.startsOnNewLine = startsOnNewLine; return node; } diff --git a/src/services/services.ts b/src/services/services.ts index b3eb58bdcb3..3efecd68572 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3062,7 +3062,7 @@ namespace ts { } return true; } - else if(jsxContainer) { + else if (jsxContainer) { let attrsType: Type; if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) { // Cursor is inside a JSX self-closing element or opening element @@ -3162,7 +3162,7 @@ namespace ts { switch (previousToken.kind) { case SyntaxKind.CommaToken: return containingNodeKind === SyntaxKind.CallExpression // func( a, | - || containingNodeKind === SyntaxKind.Constructor // constructor( a, | public, protected, private keywords are allowed here, so show completion + || containingNodeKind === SyntaxKind.Constructor // constructor( a, | /* public, protected, private keywords are allowed here, so show completion */ || containingNodeKind === SyntaxKind.NewExpression // new C(a, | || containingNodeKind === SyntaxKind.ArrayLiteralExpression // [a, | || containingNodeKind === SyntaxKind.BinaryExpression // let x = (a, | @@ -3173,10 +3173,12 @@ namespace ts { || containingNodeKind === SyntaxKind.Constructor // constructor( | || containingNodeKind === SyntaxKind.NewExpression // new C(a| || containingNodeKind === SyntaxKind.ParenthesizedExpression // let x = (a| - || containingNodeKind === SyntaxKind.ParenthesizedType; // function F(pred: (a| this can become an arrow function, where 'a' is the argument + || containingNodeKind === SyntaxKind.ParenthesizedType; // function F(pred: (a| /* this can become an arrow function, where 'a' is the argument */ case SyntaxKind.OpenBracketToken: - return containingNodeKind === SyntaxKind.ArrayLiteralExpression; // [ | + return containingNodeKind === SyntaxKind.ArrayLiteralExpression // [ | + || containingNodeKind === SyntaxKind.IndexSignature // [ | : string ] + || containingNodeKind === SyntaxKind.ComputedPropertyName // [ | /* this can become an index signature */ case SyntaxKind.ModuleKeyword: // module | case SyntaxKind.NamespaceKeyword: // namespace | @@ -7385,8 +7387,8 @@ namespace ts { } let proto = kind === SyntaxKind.SourceFile ? new SourceFileObject() : new NodeObject(); proto.kind = kind; - proto.pos = 0; - proto.end = 0; + proto.pos = -1; + proto.end = -1; proto.flags = 0; proto.parent = undefined; Node.prototype = proto; diff --git a/tests/baselines/reference/restParamModifier.errors.txt b/tests/baselines/reference/restParamModifier.errors.txt new file mode 100644 index 00000000000..87c73fcdc71 --- /dev/null +++ b/tests/baselines/reference/restParamModifier.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/restParamModifier.ts(2,17): error TS2370: A rest parameter must be of an array type. +tests/cases/compiler/restParamModifier.ts(2,27): error TS1005: '=' expected. +tests/cases/compiler/restParamModifier.ts(2,27): error TS2304: Cannot find name 'rest'. +tests/cases/compiler/restParamModifier.ts(2,31): error TS1005: ',' expected. +tests/cases/compiler/restParamModifier.ts(2,39): error TS1005: '=' expected. + + +==== tests/cases/compiler/restParamModifier.ts (5 errors) ==== + class C { + constructor(...public rest: string[]) {} + ~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + ~~~~ +!!! error TS1005: '=' expected. + ~~~~ +!!! error TS2304: Cannot find name 'rest'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: '=' expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/restParamModifier.js b/tests/baselines/reference/restParamModifier.js new file mode 100644 index 00000000000..9a780321dc9 --- /dev/null +++ b/tests/baselines/reference/restParamModifier.js @@ -0,0 +1,12 @@ +//// [restParamModifier.ts] +class C { + constructor(...public rest: string[]) {} +} + +//// [restParamModifier.js] +var C = (function () { + function C(public, string) { + if (string === void 0) { string = []; } + } + return C; +})(); diff --git a/tests/baselines/reference/restParamModifier2.errors.txt b/tests/baselines/reference/restParamModifier2.errors.txt new file mode 100644 index 00000000000..773592fa9bf --- /dev/null +++ b/tests/baselines/reference/restParamModifier2.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/restParamModifier2.ts(2,24): error TS1005: ',' expected. + + +==== tests/cases/compiler/restParamModifier2.ts (1 errors) ==== + class C { + constructor(public ...rest: string[]) {} + ~~~ +!!! error TS1005: ',' expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/restParamModifier2.js b/tests/baselines/reference/restParamModifier2.js new file mode 100644 index 00000000000..c588c945ce4 --- /dev/null +++ b/tests/baselines/reference/restParamModifier2.js @@ -0,0 +1,15 @@ +//// [restParamModifier2.ts] +class C { + constructor(public ...rest: string[]) {} +} + +//// [restParamModifier2.js] +var C = (function () { + function C(public) { + var rest = []; + for (var _i = 1; _i < arguments.length; _i++) { + rest[_i - 1] = arguments[_i]; + } + } + return C; +})(); diff --git a/tests/cases/compiler/restParamModifier.ts b/tests/cases/compiler/restParamModifier.ts new file mode 100644 index 00000000000..220b7d36d5e --- /dev/null +++ b/tests/cases/compiler/restParamModifier.ts @@ -0,0 +1,3 @@ +class C { + constructor(...public rest: string[]) {} +} \ No newline at end of file diff --git a/tests/cases/compiler/restParamModifier2.ts b/tests/cases/compiler/restParamModifier2.ts new file mode 100644 index 00000000000..e007bc56d7c --- /dev/null +++ b/tests/cases/compiler/restParamModifier2.ts @@ -0,0 +1,3 @@ +class C { + constructor(public ...rest: string[]) {} +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInIndexSignature01.ts b/tests/cases/fourslash/completionListInIndexSignature01.ts new file mode 100644 index 00000000000..2db28505b3e --- /dev/null +++ b/tests/cases/fourslash/completionListInIndexSignature01.ts @@ -0,0 +1,20 @@ +/// + +////interface I { +//// [/*1*/]: T; +//// [/*2*/]: T; +////} +//// +////class C { +//// [/*3*/]: string; +//// [str/*4*/: string]: number; +////} +//// +////type T = { +//// [x/*5*/yz: number]: boolean; +//// [/*6*/ + +for (let marker of test.markers()) { + goTo.position(marker.position); + verify.completionListAllowsNewIdentifier(); +} \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInIndexSignature02.ts b/tests/cases/fourslash/completionListInIndexSignature02.ts new file mode 100644 index 00000000000..d3b65dc7759 --- /dev/null +++ b/tests/cases/fourslash/completionListInIndexSignature02.ts @@ -0,0 +1,19 @@ +/// + +////interface I { +//// [x: /*1*/]: T; +//// [: /*2*/]: T +////} +//// +////class C { +//// [a: /*3*/]: string; +//// [str: string/*4*/]: number; +////} +//// +////type T = { +//// [xyz: /*5*/ + +for (let marker of test.markers()) { + goTo.position(marker.position); + verify.not.completionListAllowsNewIdentifier(); +} \ No newline at end of file