Skip to content

Commit

Permalink
addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vladima committed Oct 17, 2016
1 parent 135c6b5 commit 668c3f8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 80 deletions.
1 change: 1 addition & 0 deletions scripts/buildProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function generateProtocolFile(protocolTs: string, typeScriptServicesDts: string)
}
protocolDts += "\nimport protocol = ts.server.protocol;";
protocolDts += "\nexport = protocol;";
protocolDts += "\nexport as namespace protocol;";
// do sanity check and try to compile generated text as standalone program
const sanityCheckProgram = getProgramWithProtocolText(protocolDts, /*includeTypeScriptServices*/ false);
const diagnostics = [...sanityCheckProgram.getSyntacticDiagnostics(), ...sanityCheckProgram.getSemanticDiagnostics(), ...sanityCheckProgram.getGlobalDiagnostics()];
Expand Down
120 changes: 53 additions & 67 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,6 @@
namespace ts {
/* @internal */
export const compileOnSaveCommandLineOption: CommandLineOption = { name: "compileOnSave", type: "boolean" };
/* @internal */
export const jsxCompilerOption: CommandLineOptionOfCustomType = {
name: "jsx",
type: createMap({
"preserve": JsxEmit.Preserve,
"react": JsxEmit.React
}),
paramType: Diagnostics.KIND,
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
};

/* @internal */
export const moduleCommandLineOption: CommandLineOptionOfCustomType = {
name: "module",
shortName: "m",
type: createMap({
"none": ModuleKind.None,
"commonjs": ModuleKind.CommonJS,
"amd": ModuleKind.AMD,
"system": ModuleKind.System,
"umd": ModuleKind.UMD,
"es6": ModuleKind.ES6,
"es2015": ModuleKind.ES2015,
}),
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
paramType: Diagnostics.KIND,
};

/* @internal */
export const newLineCommandLineOption: CommandLineOptionOfCustomType = {
name: "newLine",
type: createMap({
"crlf": NewLineKind.CarriageReturnLineFeed,
"lf": NewLineKind.LineFeed
}),
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
paramType: Diagnostics.NEWLINE,
};

/* @internal */
export const moduleResolutionCommandLineOption: CommandLineOptionOfCustomType = {
name: "moduleResolution",
type: createMap({
"node": ModuleResolutionKind.NodeJs,
"classic": ModuleResolutionKind.Classic,
}),
description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
};

/* @internal */
export const targetCommandLineOption: CommandLineOptionOfCustomType = {
name: "target",
shortName: "t",
type: createMap({
"es3": ScriptTarget.ES3,
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es2015": ScriptTarget.ES2015,
}),
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
paramType: Diagnostics.VERSION,
};

/* @internal */
export const optionDeclarations: CommandLineOption[] = [
Expand Down Expand Up @@ -125,7 +63,15 @@ namespace ts {
name: "inlineSources",
type: "boolean",
},
jsxCompilerOption,
{
name: "jsx",
type: createMap({
"preserve": JsxEmit.Preserve,
"react": JsxEmit.React
}),
paramType: Diagnostics.KIND,
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
},
{
name: "reactNamespace",
type: "string",
Expand All @@ -146,8 +92,30 @@ namespace ts {
description: Diagnostics.Specify_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
paramType: Diagnostics.LOCATION,
},
moduleCommandLineOption,
newLineCommandLineOption,
{
name: "module",
shortName: "m",
type: createMap({
"none": ModuleKind.None,
"commonjs": ModuleKind.CommonJS,
"amd": ModuleKind.AMD,
"system": ModuleKind.System,
"umd": ModuleKind.UMD,
"es6": ModuleKind.ES6,
"es2015": ModuleKind.ES2015,
}),
description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_system_umd_or_es2015,
paramType: Diagnostics.KIND,
},
{
name: "newLine",
type: createMap({
"crlf": NewLineKind.CarriageReturnLineFeed,
"lf": NewLineKind.LineFeed
}),
description: Diagnostics.Specify_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix,
paramType: Diagnostics.NEWLINE,
},
{
name: "noEmit",
type: "boolean",
Expand Down Expand Up @@ -287,7 +255,18 @@ namespace ts {
description: Diagnostics.Do_not_emit_declarations_for_code_that_has_an_internal_annotation,
experimental: true
},
targetCommandLineOption,
{
name: "target",
shortName: "t",
type: createMap({
"es3": ScriptTarget.ES3,
"es5": ScriptTarget.ES5,
"es6": ScriptTarget.ES6,
"es2015": ScriptTarget.ES2015,
}),
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES2015,
paramType: Diagnostics.VERSION,
},
{
name: "version",
shortName: "v",
Expand All @@ -311,7 +290,14 @@ namespace ts {
experimental: true,
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
},
moduleResolutionCommandLineOption,
{
name: "moduleResolution",
type: createMap({
"node": ModuleResolutionKind.NodeJs,
"classic": ModuleResolutionKind.Classic,
}),
description: Diagnostics.Specify_module_resolution_strategy_Colon_node_Node_js_or_classic_TypeScript_pre_1_6,
},
{
name: "allowUnusedLabels",
type: "boolean",
Expand Down
36 changes: 23 additions & 13 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@ namespace ts.server {
(event: ProjectServiceEvent): void;
}

function prepareConvertersForEnumLikeCompilerOptions(commandLineOptions: CommandLineOption[]): Map<Map<number>> {
const map: Map<Map<number>> = createMap<Map<number>>();
for (const option of commandLineOptions) {
if (typeof option.type === "object") {
const optionMap = <Map<number>>option.type;
// verify that map contains only numbers
for (const id in optionMap) {
Debug.assert(typeof optionMap[id] === "number");
}
map[option.name] = optionMap;
}
}
return map;
}

const compilerOptionConverters = prepareConvertersForEnumLikeCompilerOptions(optionDeclarations);
const indentStyle = createMap({
"none": IndentStyle.None,
"block": IndentStyle.Block,
Expand All @@ -32,20 +48,14 @@ namespace ts.server {
}

export function convertCompilerOptions(protocolOptions: protocol.ExternalProjectCompilerOptions): CompilerOptions & protocol.CompileOnSaveMixin {
protocolOptions.target = convertCompilerOptionEnum(targetCommandLineOption, protocolOptions.target);
protocolOptions.module = convertCompilerOptionEnum(moduleCommandLineOption, protocolOptions.module);
protocolOptions.moduleResolution = convertCompilerOptionEnum(moduleResolutionCommandLineOption, protocolOptions.moduleResolution);
protocolOptions.jsx = convertCompilerOptionEnum(jsxCompilerOption, protocolOptions.jsx);
protocolOptions.newLine = convertCompilerOptionEnum(newLineCommandLineOption, protocolOptions.newLine);
return <any>protocolOptions;
}

function convertCompilerOptionEnum(option: CommandLineOptionOfCustomType, value: string | number): number {
if (typeof value === "string") {
value = <number>option.type[value.toLowerCase()];
Debug.assert(value !== undefined);
for (const id in compilerOptionConverters) {
const propertyValue = protocolOptions[id];
if (typeof propertyValue === "string") {
const mappedValues = compilerOptionConverters[id];
protocolOptions[id] = mappedValues[propertyValue.toLowerCase()];
}
}
return value;
return <any>protocolOptions;
}

export function tryConvertScriptKindName(scriptKindName: protocol.ScriptKindName | ScriptKind): ScriptKind {
Expand Down

0 comments on commit 668c3f8

Please sign in to comment.