Skip to content

Commit db6e46d

Browse files
committed
Removes trailing comma logic and fixes default values
1 parent 5daf3f1 commit db6e46d

7 files changed

Lines changed: 268 additions & 266 deletions

File tree

Jakefile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ var harnessSources = harnessCoreSources.concat([
143143
"convertToBase64.ts",
144144
"transpile.ts",
145145
"projectInit.ts",
146-
"jsonWithCommentsAndTrailingCommas.ts"
146+
"jsonWithComments.ts"
147147
].map(function (f) {
148148
return path.join(unittestsDirectory, f);
149149
})).concat([

src/compiler/commandLineParser.ts

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -386,49 +386,35 @@ namespace ts {
386386
continue;
387387
}
388388

389-
if(ch === CharacterCodes.slash) {
390-
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
391-
pos += 2;
389+
switch (ch) {
390+
case CharacterCodes.slash:
391+
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
392+
pos += 2;
392393

393-
while (pos <= end) {
394-
if (isLineBreak(text.charCodeAt(pos))) {
395-
break;
394+
while (pos <= end) {
395+
if (isLineBreak(text.charCodeAt(pos))) {
396+
break;
397+
}
398+
pos++;
396399
}
397-
pos++;
400+
break;
398401
}
399-
continue;
400-
}
401-
else if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
402-
pos += 2;
402+
else if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
403+
pos += 2;
403404

404-
while (pos <= end) {
405-
ch = text.charCodeAt(pos);
405+
while (pos <= end) {
406+
ch = text.charCodeAt(pos);
406407

407-
if (ch === CharacterCodes.asterisk &&
408-
text.charCodeAt(pos + 1) === CharacterCodes.slash) {
408+
if (ch === CharacterCodes.asterisk &&
409+
text.charCodeAt(pos + 1) === CharacterCodes.slash) {
409410

410-
pos += 2;
411-
break;
411+
pos += 2;
412+
break;
413+
}
414+
pos++;
412415
}
413-
pos++;
416+
break;
414417
}
415-
continue;
416-
}
417-
}
418-
419-
if (pendingCommaInsertion) {
420-
if (ch !== CharacterCodes.closeBracket &&
421-
ch !== CharacterCodes.closeBrace) {
422-
423-
result += ',';
424-
}
425-
pendingCommaInsertion = false;
426-
}
427-
428-
switch (ch) {
429-
case CharacterCodes.comma:
430-
pendingCommaInsertion = true;
431-
break;
432418

433419
case CharacterCodes.doubleQuote:
434420
result += text[pos];

src/compiler/emitter.ts

Lines changed: 0 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -3,190 +3,6 @@
33

44
/* @internal */
55
namespace ts {
6-
export const defaultInitCompilerOptions: CompilerOptions = {
7-
module: ModuleKind.CommonJS,
8-
target: ScriptTarget.ES3,
9-
noImplicitAny: true,
10-
outDir: "built",
11-
rootDir: ".",
12-
sourceMap: false,
13-
}
14-
15-
export function buildConfigFile(writer: EmitTextWriter, compilerOptions: CompilerOptions, fileNames?: string[], excludes?: string[]) {
16-
compilerOptions = extend(compilerOptions, defaultInitCompilerOptions);
17-
let { write, writeLine, increaseIndent, decreaseIndent } = writer;
18-
let { optionNameMap } = getOptionNameMap();
19-
writeTsConfigDotJsonFile();
20-
21-
function writeTsConfigDotJsonFile() {
22-
write("{");
23-
writeLine();
24-
increaseIndent();
25-
writeCompilerOptions();
26-
if (fileNames && fileNames.length > 0) {
27-
write(",");
28-
writeLine();
29-
writeFileNames();
30-
}
31-
if (excludes) {
32-
write(",");
33-
writeLine();
34-
writeExcludeOptions();
35-
}
36-
writeLine();
37-
decreaseIndent();
38-
write("}");
39-
}
40-
41-
function writeCompilerOptions() {
42-
write(`"compilerOptions": {`);
43-
writeLine();
44-
increaseIndent();
45-
46-
for (var option in compilerOptions) {
47-
switch (option) {
48-
case "init":
49-
case "watch":
50-
case "help":
51-
case "version":
52-
continue;
53-
54-
case "module":
55-
case "target":
56-
case "newLine":
57-
writeComplexCompilerOption(option);
58-
break;
59-
60-
default:
61-
writeSimpleCompilerOption(option);
62-
}
63-
}
64-
65-
decreaseIndent();
66-
write("}");
67-
}
68-
69-
function writeOptionalOptionDescription(option: string) {
70-
option = option.toLowerCase();
71-
if (optionNameMap[option].description &&
72-
optionNameMap[option].description.key) {
73-
74-
write(`// ${optionNameMap[option].description.key}`);
75-
writeLine();
76-
}
77-
}
78-
79-
/**
80-
* Write simple compiler option. A simple compiler option is an option
81-
* with boolean or non string set value.
82-
*/
83-
function writeSimpleCompilerOption(option: string) {
84-
writeOptionalOptionDescription(option);
85-
86-
write(`"${option}": `);
87-
if (typeof compilerOptions[option] === "string") {
88-
write(`"${compilerOptions[option]}",`);
89-
writeLine();
90-
}
91-
else {
92-
if (compilerOptions[option]) {
93-
write("true,");
94-
}
95-
else {
96-
write("false,");
97-
}
98-
writeLine();
99-
}
100-
}
101-
102-
function writeComplexCompilerOption(option: string) {
103-
writeOptionalOptionDescription(option);
104-
105-
outer: switch (option) {
106-
case "module":
107-
var moduleValue: string;
108-
switch (compilerOptions.module) {
109-
case ModuleKind.None:
110-
break outer;
111-
case ModuleKind.CommonJS:
112-
moduleValue = "commonjs";
113-
break;
114-
case ModuleKind.System:
115-
moduleValue = "system";
116-
break;
117-
case ModuleKind.UMD:
118-
moduleValue = "umd";
119-
break;
120-
default:
121-
moduleValue = "amd";
122-
break;
123-
}
124-
write(`"module": "${moduleValue}",`);
125-
writeLine();
126-
break;
127-
128-
case "target":
129-
var targetValue: string;
130-
switch (compilerOptions.target) {
131-
case ScriptTarget.ES5:
132-
targetValue = "es5";
133-
break;
134-
case ScriptTarget.ES6:
135-
targetValue = "es6";
136-
break;
137-
default:
138-
targetValue = "es3";
139-
break;
140-
}
141-
write(`"target": "${targetValue}",`);
142-
writeLine();
143-
break;
144-
145-
case "newLine":
146-
var newlineValue: string;
147-
switch (compilerOptions.newLine) {
148-
case NewLineKind.CarriageReturnLineFeed:
149-
newlineValue = "CRLF";
150-
break;
151-
default:
152-
newlineValue = "LF";
153-
break;
154-
}
155-
write(`"newLine": "${newlineValue}",`);
156-
writeLine();
157-
break;
158-
}
159-
}
160-
161-
function writeFileNames() {
162-
write(`"files": [`);
163-
writeLine();
164-
increaseIndent();
165-
166-
for (let fileName of fileNames) {
167-
write(`"${fileName}",`);
168-
writeLine();
169-
}
170-
171-
decreaseIndent();
172-
write("]");
173-
}
174-
175-
function writeExcludeOptions() {
176-
write(`"exclude": [`);
177-
writeLine();
178-
increaseIndent();
179-
180-
for (let exclude of excludes) {
181-
write(`"${exclude}",`);
182-
writeLine();
183-
}
184-
185-
decreaseIndent();
186-
write("]");
187-
}
188-
}
189-
1906
export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) {
1917
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
1928
}

0 commit comments

Comments
 (0)