Skip to content

Conversation

@vladima
Copy link
Contributor

@vladima vladima commented Oct 15, 2016

// cc @dbaeumer, @mhegazy
This PR:

  • removes enums from the protocol file and converts all enums into unions of literal types
  • converts protocol.d.ts to module

now generated protocol.d.ts looks like this

if (extraDeclarations) {
protocolDts += extraDeclarations;
}
protocolDts += "\nimport protocol = ts.server.protocol;";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export as namespace protocol

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

}

export function convertCompilerOptions(protocolOptions: protocol.ExternalProjectCompilerOptions): CompilerOptions & protocol.CompileOnSaveMixin {
protocolOptions.target = convertCompilerOptionEnum(targetCommandLineOption, protocolOptions.target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this in a more generic way? we have the types for the options as a whole, so we can just go through them once and build a map of things we want to convert, then do this on the fly?

Copy link
Contributor Author

@vladima vladima Oct 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure that I understand what you mean and how it will be beneficial. We already reuse maps that we've populated for compiler options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now if i add a new compiler option, i need to add it to commandline-parser and here as well. can i do it in one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@vladima vladima merged commit ea3cbfb into release-2.0.5 Oct 17, 2016
@vladima vladima deleted the vladima/literals-in-protocol branch October 17, 2016 22:46
vladima added a commit that referenced this pull request Oct 17, 2016
switch enums in protocol to unions of literal types
vladima added a commit that referenced this pull request Oct 17, 2016

const compilerOptionConverters = prepareConvertersForEnumLikeCompilerOptions(optionDeclarations);
const indentStyle = createMap({
"none": IndentStyle.None,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use the lowercase names here and call protocolOptions.indentStyle.toLowerCase() later? Why not just use "None" etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we cannot guarantee that all callers will use proper casing for these values. It can be enforced for .ts sources but other consumers cannot be checked so we try to be tolerant

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants