Skip to content

Commit 8d771ca

Browse files
committed
Merge branch 'master' into ownJsonParsing
2 parents 7db76ed + 2c3c4dd commit 8d771ca

File tree

68 files changed

+3351
-406
lines changed

Some content is hidden

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

68 files changed

+3351
-406
lines changed

Jakefile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var harnessSources = harnessCoreSources.concat([
129129
"initializeTSConfig.ts",
130130
"printer.ts",
131131
"textChanges.ts",
132+
"telemetry.ts",
132133
"transform.ts",
133134
"customTransforms.ts",
134135
].map(function (f) {
@@ -1079,7 +1080,7 @@ var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js';
10791080
file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function () {
10801081
var temp = builtLocalDirectory + 'temp';
10811082
jake.mkdirP(temp);
1082-
var options = "--types --outdir " + temp + ' ' + loggedIOpath;
1083+
var options = "--target es5 --lib es6 --types --outdir " + temp + ' ' + loggedIOpath;
10831084
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " ";
10841085
console.log(cmd + "\n");
10851086
var ex = jake.createExec([cmd]);
@@ -1093,7 +1094,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function () {
10931094

10941095
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
10951096
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js';
1096-
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true);
1097+
compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true, { lib: "es6", types: ["node"] });
10971098

10981099
desc("Builds an instrumented tsc.js");
10991100
task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function () {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"gulp-insert": "latest",
6060
"gulp-newer": "latest",
6161
"gulp-sourcemaps": "latest",
62-
"gulp-typescript": "3.1.5",
62+
"gulp-typescript": "latest",
6363
"into-stream": "latest",
6464
"istanbul": "latest",
6565
"jake": "latest",
@@ -74,7 +74,7 @@
7474
"through2": "latest",
7575
"travis-fold": "latest",
7676
"ts-node": "latest",
77-
"tslint": "next",
77+
"tslint": "latest",
7878
"typescript": "next"
7979
},
8080
"scripts": {

src/compiler/binder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,10 @@ namespace ts {
21782178
case SyntaxKind.JSDocRecordMember:
21792179
return bindPropertyWorker(node as JSDocRecordMember);
21802180
case SyntaxKind.JSDocPropertyTag:
2181-
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2181+
return declareSymbolAndAddToSymbolTable(node as JSDocPropertyTag,
2182+
(node as JSDocPropertyTag).isBracketed || ((node as JSDocPropertyTag).typeExpression && (node as JSDocPropertyTag).typeExpression.type.kind === SyntaxKind.JSDocOptionalType) ?
2183+
SymbolFlags.Property | SymbolFlags.Optional : SymbolFlags.Property,
2184+
SymbolFlags.PropertyExcludes);
21822185
case SyntaxKind.JSDocFunctionType:
21832186
return bindFunctionOrConstructorType(<SignatureDeclaration>node);
21842187
case SyntaxKind.JSDocTypeLiteral:
@@ -3593,4 +3596,4 @@ namespace ts {
35933596
return TransformFlags.NodeExcludes;
35943597
}
35953598
}
3596-
}
3599+
}

src/compiler/checker.ts

Lines changed: 161 additions & 129 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ namespace ts {
692692
return typeAcquisition;
693693
}
694694

695-
/* @internal */
696-
export function getOptionNameMap(): OptionNameMap {
695+
function getOptionNameMap(): OptionNameMap {
697696
if (optionNameMapCache) {
698697
return optionNameMapCache;
699698
}
@@ -750,7 +749,6 @@ namespace ts {
750749
const options: CompilerOptions = {};
751750
const fileNames: string[] = [];
752751
const errors: Diagnostic[] = [];
753-
const { optionNameMap, shortOptionNames } = getOptionNameMap();
754752

755753
parseStrings(commandLine);
756754
return {
@@ -762,21 +760,13 @@ namespace ts {
762760
function parseStrings(args: string[]) {
763761
let i = 0;
764762
while (i < args.length) {
765-
let s = args[i];
763+
const s = args[i];
766764
i++;
767765
if (s.charCodeAt(0) === CharacterCodes.at) {
768766
parseResponseFile(s.slice(1));
769767
}
770768
else if (s.charCodeAt(0) === CharacterCodes.minus) {
771-
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
772-
773-
// Try to translate short option names to their full equivalents.
774-
const short = shortOptionNames.get(s);
775-
if (short !== undefined) {
776-
s = short;
777-
}
778-
779-
const opt = optionNameMap.get(s);
769+
const opt = getOptionFromName(s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1), /*allowShort*/ true);
780770
if (opt) {
781771
if (opt.isTSConfigOnly) {
782772
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name));
@@ -864,6 +854,19 @@ namespace ts {
864854
}
865855
}
866856

857+
function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
858+
optionName = optionName.toLowerCase();
859+
const { optionNameMap, shortOptionNames } = getOptionNameMap();
860+
// Try to translate short option names to their full equivalents.
861+
if (allowShort) {
862+
const short = shortOptionNames.get(optionName);
863+
if (short !== undefined) {
864+
optionName = short;
865+
}
866+
}
867+
return optionNameMap.get(optionName);
868+
}
869+
867870
/**
868871
* Read tsconfig.json file
869872
* @param fileName The path to the config file
@@ -2173,4 +2176,42 @@ namespace ts {
21732176
function caseInsensitiveKeyMapper(key: string) {
21742177
return key.toLowerCase();
21752178
}
2179+
2180+
/**
2181+
* Produces a cleaned version of compiler options with personally identifiying info (aka, paths) removed.
2182+
* Also converts enum values back to strings.
2183+
*/
2184+
/* @internal */
2185+
export function convertCompilerOptionsForTelemetry(opts: ts.CompilerOptions): ts.CompilerOptions {
2186+
const out: ts.CompilerOptions = {};
2187+
for (const key in opts) if (opts.hasOwnProperty(key)) {
2188+
const type = getOptionFromName(key);
2189+
if (type !== undefined) { // Ignore unknown options
2190+
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
2191+
}
2192+
}
2193+
return out;
2194+
}
2195+
2196+
function getOptionValueWithEmptyStrings(value: any, option: CommandLineOption): {} {
2197+
switch (option.type) {
2198+
case "object": // "paths". Can't get any useful information from the value since we blank out strings, so just return "".
2199+
return "";
2200+
case "string": // Could be any arbitrary string -- use empty string instead.
2201+
return "";
2202+
case "number": // Allow numbers, but be sure to check it's actually a number.
2203+
return typeof value === "number" ? value : "";
2204+
case "boolean":
2205+
return typeof value === "boolean" ? value : "";
2206+
case "list":
2207+
const elementType = (option as CommandLineOptionOfListType).element;
2208+
return ts.isArray(value) ? value.map(v => getOptionValueWithEmptyStrings(v, elementType)) : "";
2209+
default:
2210+
return ts.forEachEntry(option.type, (optionEnumValue, optionStringValue) => {
2211+
if (optionEnumValue === value) {
2212+
return optionStringValue;
2213+
}
2214+
});
2215+
}
2216+
}
21762217
}

src/compiler/core.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,18 @@ namespace ts {
521521
return result || array;
522522
}
523523

524+
export function mapDefined<T>(array: ReadonlyArray<T>, mapFn: (x: T, i: number) => T | undefined): ReadonlyArray<T> {
525+
const result: T[] = [];
526+
for (let i = 0; i < array.length; i++) {
527+
const item = array[i];
528+
const mapped = mapFn(item, i);
529+
if (mapped !== undefined) {
530+
result.push(mapped);
531+
}
532+
}
533+
return result;
534+
}
535+
524536
/**
525537
* Computes the first matching span of elements and returns a tuple of the first span
526538
* and the remaining elements.

src/compiler/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ namespace ts {
303303
: node;
304304
}
305305

306-
export function createProperty(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression) {
306+
export function createProperty(decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: string | PropertyName, questionToken: QuestionToken | undefined, type: TypeNode | undefined, initializer: Expression | undefined) {
307307
const node = <PropertyDeclaration>createSynthesizedNode(SyntaxKind.PropertyDeclaration);
308308
node.decorators = asNodeArray(decorators);
309309
node.modifiers = asNodeArray(modifiers);
@@ -314,7 +314,7 @@ namespace ts {
314314
return node;
315315
}
316316

317-
export function updateProperty(node: PropertyDeclaration, decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: PropertyName, type: TypeNode | undefined, initializer: Expression) {
317+
export function updateProperty(node: PropertyDeclaration, decorators: Decorator[] | undefined, modifiers: Modifier[] | undefined, name: PropertyName, type: TypeNode | undefined, initializer: Expression | undefined) {
318318
return node.decorators !== decorators
319319
|| node.modifiers !== modifiers
320320
|| node.name !== name

src/compiler/parser.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,7 +6108,10 @@ namespace ts {
61086108
case SyntaxKind.OpenBraceToken:
61096109
return parseJSDocRecordType();
61106110
case SyntaxKind.FunctionKeyword:
6111-
return parseJSDocFunctionType();
6111+
if (lookAhead(nextTokenIsOpenParen)) {
6112+
return parseJSDocFunctionType();
6113+
}
6114+
break;
61126115
case SyntaxKind.DotDotDotToken:
61136116
return parseJSDocVariadicType();
61146117
case SyntaxKind.NewKeyword:
@@ -6124,7 +6127,6 @@ namespace ts {
61246127
case SyntaxKind.NullKeyword:
61256128
case SyntaxKind.UndefinedKeyword:
61266129
case SyntaxKind.NeverKeyword:
6127-
case SyntaxKind.ObjectKeyword:
61286130
return parseTokenNode<JSDocType>();
61296131
case SyntaxKind.StringLiteral:
61306132
case SyntaxKind.NumericLiteral:
@@ -6664,10 +6666,7 @@ namespace ts {
66646666
});
66656667
}
66666668

6667-
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6668-
let typeExpression = tryParseTypeExpression();
6669-
skipWhitespace();
6670-
6669+
function parseBracketNameInPropertyAndParamTag() {
66716670
let name: Identifier;
66726671
let isBracketed: boolean;
66736672
// Looking for something like '[foo]' or 'foo'
@@ -6686,6 +6685,14 @@ namespace ts {
66866685
else if (tokenIsIdentifierOrKeyword(token())) {
66876686
name = parseJSDocIdentifierName();
66886687
}
6688+
return { name, isBracketed };
6689+
}
6690+
6691+
function parseParamTag(atToken: AtToken, tagName: Identifier) {
6692+
let typeExpression = tryParseTypeExpression();
6693+
skipWhitespace();
6694+
6695+
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
66896696

66906697
if (!name) {
66916698
parseErrorAtPosition(scanner.getStartPos(), 0, Diagnostics.Identifier_expected);
@@ -6742,8 +6749,9 @@ namespace ts {
67426749
function parsePropertyTag(atToken: AtToken, tagName: Identifier): JSDocPropertyTag {
67436750
const typeExpression = tryParseTypeExpression();
67446751
skipWhitespace();
6745-
const name = parseJSDocIdentifierName();
6752+
const { name, isBracketed } = parseBracketNameInPropertyAndParamTag();
67466753
skipWhitespace();
6754+
67476755
if (!name) {
67486756
parseErrorAtPosition(scanner.getStartPos(), /*length*/ 0, Diagnostics.Identifier_expected);
67496757
return undefined;
@@ -6754,6 +6762,7 @@ namespace ts {
67546762
result.tagName = tagName;
67556763
result.name = name;
67566764
result.typeExpression = typeExpression;
6765+
result.isBracketed = isBracketed;
67576766
return finishNode(result);
67586767
}
67596768

@@ -6795,7 +6804,7 @@ namespace ts {
67956804
const jsDocTypeReference = <JSDocTypeReference>typeExpression.type;
67966805
if (jsDocTypeReference.name.kind === SyntaxKind.Identifier) {
67976806
const name = <Identifier>jsDocTypeReference.name;
6798-
if (name.text === "Object") {
6807+
if (name.text === "Object" || name.text === "object") {
67996808
typedefTag.jsDocTypeLiteral = scanChildTags();
68006809
}
68016810
}

src/compiler/scanner.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ namespace ts {
429429
case CharacterCodes.slash:
430430
// starts of normal trivia
431431
case CharacterCodes.lessThan:
432+
case CharacterCodes.bar:
432433
case CharacterCodes.equals:
433434
case CharacterCodes.greaterThan:
434435
// Starts of conflict marker trivia
@@ -496,6 +497,7 @@ namespace ts {
496497
break;
497498

498499
case CharacterCodes.lessThan:
500+
case CharacterCodes.bar:
499501
case CharacterCodes.equals:
500502
case CharacterCodes.greaterThan:
501503
if (isConflictMarkerTrivia(text, pos)) {
@@ -562,12 +564,12 @@ namespace ts {
562564
}
563565
}
564566
else {
565-
Debug.assert(ch === CharacterCodes.equals);
566-
// Consume everything from the start of the mid-conflict marker to the start of the next
567-
// end-conflict marker.
567+
Debug.assert(ch === CharacterCodes.bar || ch === CharacterCodes.equals);
568+
// Consume everything from the start of a ||||||| or ======= marker to the start
569+
// of the next ======= or >>>>>>> marker.
568570
while (pos < len) {
569-
const ch = text.charCodeAt(pos);
570-
if (ch === CharacterCodes.greaterThan && isConflictMarkerTrivia(text, pos)) {
571+
const currentChar = text.charCodeAt(pos);
572+
if ((currentChar === CharacterCodes.equals || currentChar === CharacterCodes.greaterThan) && currentChar !== ch && isConflictMarkerTrivia(text, pos)) {
571573
break;
572574
}
573575

@@ -1562,6 +1564,16 @@ namespace ts {
15621564
pos++;
15631565
return token = SyntaxKind.OpenBraceToken;
15641566
case CharacterCodes.bar:
1567+
if (isConflictMarkerTrivia(text, pos)) {
1568+
pos = scanConflictMarkerTrivia(text, pos, error);
1569+
if (skipTrivia) {
1570+
continue;
1571+
}
1572+
else {
1573+
return token = SyntaxKind.ConflictMarkerTrivia;
1574+
}
1575+
}
1576+
15651577
if (text.charCodeAt(pos + 1) === CharacterCodes.bar) {
15661578
return pos += 2, token = SyntaxKind.BarBarToken;
15671579
}

0 commit comments

Comments
 (0)