From dd0ed44b9aaa7dcd24bb415a5a6a241cd2d6061f Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 23 Jan 2017 17:40:20 +0100 Subject: [PATCH 1/7] Add option to output .js files while preserving jsx This commit adds the ability to preserve jsx in source code, but also to output .js files rather than .jsx files. This is useful for react-native which does not support .jsx files. --- lib/protocol.d.ts | 5 +- src/compiler/commandLineParser.ts | 3 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 3 +- src/harness/unittests/commandLineParsing.ts | 2 +- .../convertCompilerOptionsFromJson.ts | 2 +- src/harness/unittests/matchFiles.ts | 54 ++++++++++++++++- src/server/protocol.ts | 9 +-- tests/cases/unittests/matchFiles.ts | 58 ++++++++++++++++++- 9 files changed, 125 insertions(+), 13 deletions(-) diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index d6c0246af34c9..66c2ef5c8db0f 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1798,9 +1798,10 @@ declare namespace ts.server.protocol { namespace JsxEmit { type None = "None"; type Preserve = "Preserve"; + type PreserveWithJsExtension = "PreserveWithJsExtension"; type React = "React"; } - type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React; + type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.PreserveWithJsExtension; namespace ModuleKind { type None = "None"; type CommonJS = "CommonJS"; @@ -1880,4 +1881,4 @@ declare namespace ts { } import protocol = ts.server.protocol; export = protocol; -export as namespace protocol; \ No newline at end of file +export as namespace protocol; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b222df53630e0..7c69676d6f0f2 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -67,10 +67,11 @@ namespace ts { name: "jsx", type: createMapFromTemplate({ "preserve": JsxEmit.Preserve, + "preservewithjsextension": JsxEmit.PreserveWithJsExtension, "react": JsxEmit.React }), paramType: Diagnostics.KIND, - description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react, + description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_preserveWithJsExtension_or_react, }, { name: "reactNamespace", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 43bb7415c8839..6646017e73ddf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2713,7 +2713,7 @@ "category": "Message", "code": 6079 }, - "Specify JSX code generation: 'preserve' or 'react'": { + "Specify JSX code generation: 'preserve', 'preserveWithJsExtension', or 'react'": { "category": "Message", "code": 6080 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c16c199d3eb22..9024b7c1b13cd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3298,7 +3298,8 @@ export const enum JsxEmit { None = 0, Preserve = 1, - React = 2 + React = 2, + PreserveWithJsExtension = 3 } export const enum NewLineKind { diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 8c691992043db..34a096628f9fc 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -87,7 +87,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'preservewithjsextension', 'react'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index f44dc259710e5..cbfa47180f330 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -94,7 +94,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'preservewithjsextension', 'react'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index c562fcefe914f..2b4bbfd4ee6d7 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -909,6 +909,31 @@ namespace ts { const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); assertParsed(actual, expected); }); + it("with jsx=preserveWithJsExtension, allowJs=false", () => { + const json = { + compilerOptions: { + jsx: "preserveWithJsExtension", + allowJs: false + } + }; + const expected: ts.ParsedCommandLine = { + options: { + jsx: ts.JsxEmit.PreserveWithJsExtension, + allowJs: false + }, + errors: [], + fileNames: [ + "c:/dev/a.ts", + "c:/dev/b.tsx", + "c:/dev/c.tsx", + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); + assertParsed(actual, expected); + }); it("with jsx=none, allowJs=true", () => { const json = { compilerOptions: { @@ -961,6 +986,33 @@ namespace ts { const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); assertParsed(actual, expected); }); + it("with jsx=preserveWithJsExtension, allowJs=true", () => { + const json = { + compilerOptions: { + jsx: "preserveWithJsExtension", + allowJs: true + } + }; + const expected: ts.ParsedCommandLine = { + options: { + jsx: ts.JsxEmit.PreserveWithJsExtension, + allowJs: true + }, + errors: [], + fileNames: [ + "c:/dev/a.ts", + "c:/dev/b.tsx", + "c:/dev/c.tsx", + "c:/dev/d.js", + "c:/dev/e.jsx", + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); + assertParsed(actual, expected); + }); it("exclude .min.js files using wildcards", () => { const json = { compilerOptions: { @@ -1306,4 +1358,4 @@ namespace ts { }); }); }); -} \ No newline at end of file +} diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 680b81dff9986..b18c887126b1f 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -417,7 +417,7 @@ namespace ts.server.protocol { startOffset: number; /** - * Position (can be specified instead of line/offset pair) + * Position (can be specified instead of line/offset pair) */ /* @internal */ startPosition?: number; @@ -433,7 +433,7 @@ namespace ts.server.protocol { endOffset: number; /** - * Position (can be specified instead of line/offset pair) + * Position (can be specified instead of line/offset pair) */ /* @internal */ endPosition?: number; @@ -445,7 +445,7 @@ namespace ts.server.protocol { } /** - * Response for GetCodeFixes request. + * Response for GetCodeFixes request. */ export interface GetCodeFixesResponse extends Response { body?: CodeAction[]; @@ -2272,10 +2272,11 @@ namespace ts.server.protocol { export namespace JsxEmit { export type None = "None"; export type Preserve = "Preserve"; + export type PreserveWithJsExtension = "PreserveWithJsExtension"; export type React = "React"; } - export type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React; + export type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.PreserveWithJsExtension; export namespace ModuleKind { export type None = "None"; diff --git a/tests/cases/unittests/matchFiles.ts b/tests/cases/unittests/matchFiles.ts index 91be2de874765..ef982f5f2bbd7 100644 --- a/tests/cases/unittests/matchFiles.ts +++ b/tests/cases/unittests/matchFiles.ts @@ -898,6 +898,33 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); + it("with jsx=preserveWithJsExtension, allowJs=false", () => { + const json = { + compilerOptions: { + jsx: "preserveWithJsExtension", + allowJs: false + } + }; + const expected: ts.ParsedCommandLine = { + options: { + jsx: ts.JsxEmit.PreserveWithJsExtension, + allowJs: false + }, + errors: [], + fileNames: [ + "c:/dev/a.ts", + "c:/dev/b.tsx", + "c:/dev/c.tsx", + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); it("with jsx=none, allowJs=true", () => { const json = { compilerOptions: { @@ -954,6 +981,35 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); + it("with jsx=preserveWithJsExtension, allowJs=true", () => { + const json = { + compilerOptions: { + jsx: "preserveWithJsExtension", + allowJs: true + } + }; + const expected: ts.ParsedCommandLine = { + options: { + jsx: ts.JsxEmit.PreserveWithJsExtension, + allowJs: true + }, + errors: [], + fileNames: [ + "c:/dev/a.ts", + "c:/dev/b.tsx", + "c:/dev/c.tsx", + "c:/dev/d.js", + "c:/dev/e.jsx", + ], + wildcardDirectories: { + "c:/dev": ts.WatchDirectoryFlags.Recursive + } + }; + const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); + assert.deepEqual(actual.fileNames, expected.fileNames); + assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); + assert.deepEqual(actual.errors, expected.errors); + }); describe("with trailing recursive directory", () => { it("in includes", () => { const json = { @@ -1149,4 +1205,4 @@ namespace ts { }); }); }); -} \ No newline at end of file +} From 7879b22ea9b210934c50b8d87df418379dfcc435 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 23 Jan 2017 19:30:24 +0100 Subject: [PATCH 2/7] Add test case for preserveWithJsExtension --- ...utTsxFile_PreserveWithJsExtension.baseline | 26 +++++++++++++++++++ ...itOutputTsxFile_PreserveWithJsExtension.ts | 22 ++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline create mode 100644 tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts diff --git a/tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline b/tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline new file mode 100644 index 0000000000000..88fb0f0daf6a8 --- /dev/null +++ b/tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline @@ -0,0 +1,26 @@ +EmitSkipped: false +FileName : /tests/cases/fourslash/inputFile1.js.map +{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile1.js +// regular ts file +var t = 5; +var Bar = (function () { + function Bar() { + } + return Bar; +}()); +//# sourceMappingURL=inputFile1.js.mapFileName : /tests/cases/fourslash/inputFile1.d.ts +declare var t: number; +declare class Bar { + x: string; + y: number; +} + +EmitSkipped: false +FileName : /tests/cases/fourslash/inputFile2.js.map +{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,EAAG,CAAA"}FileName : /tests/cases/fourslash/inputFile2.js +var y = "my div"; +var x =
; +//# sourceMappingURL=inputFile2.js.mapFileName : /tests/cases/fourslash/inputFile2.d.ts +declare var y: string; +declare var x: any; + diff --git a/tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts b/tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts new file mode 100644 index 0000000000000..a1e4ce2d984f4 --- /dev/null +++ b/tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts @@ -0,0 +1,22 @@ +/// + +// @BaselineFile: getEmitOutputTsxFile_PreserveWithJsExtension.baseline +// @declaration: true +// @sourceMap: true +// @jsx: preserveWithJsExtension + +// @Filename: inputFile1.ts +// @emitThisFile: true +////// regular ts file +//// var t: number = 5; +//// class Bar { +//// x : string; +//// y : number +//// } + +// @Filename: inputFile2.tsx +// @emitThisFile: true +//// var y = "my div"; +//// var x =
+ +verify.baselineGetEmitOutput(); From 8d590d51916e6491191634097b8fb04f40d7d964 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 23 Jan 2017 21:42:39 +0100 Subject: [PATCH 3/7] rename preserveWithJsExtension to react-native --- lib/protocol.d.ts | 4 ++-- src/compiler/commandLineParser.ts | 4 ++-- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 2 +- src/harness/unittests/commandLineParsing.ts | 2 +- .../unittests/convertCompilerOptionsFromJson.ts | 2 +- src/harness/unittests/matchFiles.ts | 12 ++++++------ src/server/protocol.ts | 4 ++-- ...ine => getEmitOutputTsxFile_ReactNative.baseline} | 0 ...ension.ts => getEmitOutputTsxFile_ReactNative.ts} | 4 ++-- tests/cases/unittests/matchFiles.ts | 12 ++++++------ 11 files changed, 24 insertions(+), 24 deletions(-) rename tests/baselines/reference/{getEmitOutputTsxFile_PreserveWithJsExtension.baseline => getEmitOutputTsxFile_ReactNative.baseline} (100%) rename tests/cases/fourslash/{getEmitOutputTsxFile_PreserveWithJsExtension.ts => getEmitOutputTsxFile_ReactNative.ts} (75%) diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index 66c2ef5c8db0f..cd46ebcd36612 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1798,10 +1798,10 @@ declare namespace ts.server.protocol { namespace JsxEmit { type None = "None"; type Preserve = "Preserve"; - type PreserveWithJsExtension = "PreserveWithJsExtension"; + type ReactNative = "ReactNative"; type React = "React"; } - type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.PreserveWithJsExtension; + type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.ReactNative; namespace ModuleKind { type None = "None"; type CommonJS = "CommonJS"; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 7c69676d6f0f2..248726693c98a 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -67,11 +67,11 @@ namespace ts { name: "jsx", type: createMapFromTemplate({ "preserve": JsxEmit.Preserve, - "preservewithjsextension": JsxEmit.PreserveWithJsExtension, + "react-native": JsxEmit.ReactNative, "react": JsxEmit.React }), paramType: Diagnostics.KIND, - description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_preserveWithJsExtension_or_react, + description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_react_native_or_react, }, { name: "reactNamespace", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6646017e73ddf..4278784e9abf4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2713,7 +2713,7 @@ "category": "Message", "code": 6079 }, - "Specify JSX code generation: 'preserve', 'preserveWithJsExtension', or 'react'": { + "Specify JSX code generation: 'preserve', 'react-native', or 'react'": { "category": "Message", "code": 6080 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9024b7c1b13cd..6ac7d573eda74 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3299,7 +3299,7 @@ None = 0, Preserve = 1, React = 2, - PreserveWithJsExtension = 3 + ReactNative = 3 } export const enum NewLineKind { diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index 34a096628f9fc..1895fe2d60e81 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -87,7 +87,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--jsx' option must be: 'preserve', 'preservewithjsextension', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index cbfa47180f330..4e44217388306 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -94,7 +94,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--jsx' option must be: 'preserve', 'preservewithjsextension', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/harness/unittests/matchFiles.ts b/src/harness/unittests/matchFiles.ts index 2b4bbfd4ee6d7..38e5c6c439322 100644 --- a/src/harness/unittests/matchFiles.ts +++ b/src/harness/unittests/matchFiles.ts @@ -909,16 +909,16 @@ namespace ts { const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); assertParsed(actual, expected); }); - it("with jsx=preserveWithJsExtension, allowJs=false", () => { + it("with jsx=react-native, allowJs=false", () => { const json = { compilerOptions: { - jsx: "preserveWithJsExtension", + jsx: "react-native", allowJs: false } }; const expected: ts.ParsedCommandLine = { options: { - jsx: ts.JsxEmit.PreserveWithJsExtension, + jsx: ts.JsxEmit.ReactNative, allowJs: false }, errors: [], @@ -986,16 +986,16 @@ namespace ts { const actual = ts.parseJsonConfigFileContent(json, caseInsensitiveMixedExtensionHost, caseInsensitiveBasePath); assertParsed(actual, expected); }); - it("with jsx=preserveWithJsExtension, allowJs=true", () => { + it("with jsx=react-native, allowJs=true", () => { const json = { compilerOptions: { - jsx: "preserveWithJsExtension", + jsx: "react-native", allowJs: true } }; const expected: ts.ParsedCommandLine = { options: { - jsx: ts.JsxEmit.PreserveWithJsExtension, + jsx: ts.JsxEmit.ReactNative, allowJs: true }, errors: [], diff --git a/src/server/protocol.ts b/src/server/protocol.ts index b18c887126b1f..e3fe17362d7d0 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -2272,11 +2272,11 @@ namespace ts.server.protocol { export namespace JsxEmit { export type None = "None"; export type Preserve = "Preserve"; - export type PreserveWithJsExtension = "PreserveWithJsExtension"; + export type ReactNative = "ReactNative"; export type React = "React"; } - export type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.PreserveWithJsExtension; + export type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.ReactNative; export namespace ModuleKind { export type None = "None"; diff --git a/tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline b/tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline similarity index 100% rename from tests/baselines/reference/getEmitOutputTsxFile_PreserveWithJsExtension.baseline rename to tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline diff --git a/tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts b/tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts similarity index 75% rename from tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts rename to tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts index a1e4ce2d984f4..c2aac0e9d0398 100644 --- a/tests/cases/fourslash/getEmitOutputTsxFile_PreserveWithJsExtension.ts +++ b/tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts @@ -1,9 +1,9 @@ /// -// @BaselineFile: getEmitOutputTsxFile_PreserveWithJsExtension.baseline +// @BaselineFile: getEmitOutputTsxFile_ReactNative.baseline // @declaration: true // @sourceMap: true -// @jsx: preserveWithJsExtension +// @jsx: react-native // @Filename: inputFile1.ts // @emitThisFile: true diff --git a/tests/cases/unittests/matchFiles.ts b/tests/cases/unittests/matchFiles.ts index ef982f5f2bbd7..e3448136c082b 100644 --- a/tests/cases/unittests/matchFiles.ts +++ b/tests/cases/unittests/matchFiles.ts @@ -898,16 +898,16 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); - it("with jsx=preserveWithJsExtension, allowJs=false", () => { + it("with jsx=react-native, allowJs=false", () => { const json = { compilerOptions: { - jsx: "preserveWithJsExtension", + jsx: "react-native", allowJs: false } }; const expected: ts.ParsedCommandLine = { options: { - jsx: ts.JsxEmit.PreserveWithJsExtension, + jsx: ts.JsxEmit.ReactNative, allowJs: false }, errors: [], @@ -981,16 +981,16 @@ namespace ts { assert.deepEqual(actual.wildcardDirectories, expected.wildcardDirectories); assert.deepEqual(actual.errors, expected.errors); }); - it("with jsx=preserveWithJsExtension, allowJs=true", () => { + it("with jsx=react-native, allowJs=true", () => { const json = { compilerOptions: { - jsx: "preserveWithJsExtension", + jsx: "react-native", allowJs: true } }; const expected: ts.ParsedCommandLine = { options: { - jsx: ts.JsxEmit.PreserveWithJsExtension, + jsx: ts.JsxEmit.ReactNative, allowJs: true }, errors: [], From 7bf52ee1fde05154eb38042e63ac1ef95d0a415d Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 23 Jan 2017 22:08:39 +0100 Subject: [PATCH 4/7] add notifications and tests for jsx react-native es3 --- src/compiler/transformers/es5.ts | 4 ++-- tests/baselines/reference/es3-jsx-preserve.js | 11 +++++++++++ tests/baselines/reference/es3-jsx-preserve.symbols | 11 +++++++++++ tests/baselines/reference/es3-jsx-preserve.types | 13 +++++++++++++ tests/baselines/reference/es3-jsx-react-native.js | 11 +++++++++++ .../reference/es3-jsx-react-native.symbols | 11 +++++++++++ .../baselines/reference/es3-jsx-react-native.types | 13 +++++++++++++ tests/baselines/reference/es3-jsx-react.js | 11 +++++++++++ tests/baselines/reference/es3-jsx-react.symbols | 11 +++++++++++ tests/baselines/reference/es3-jsx-react.types | 13 +++++++++++++ tests/cases/compiler/es3-jsx-preserve.tsx | 9 +++++++++ tests/cases/compiler/es3-jsx-react-native.tsx | 9 +++++++++ tests/cases/compiler/es3-jsx-react.tsx | 9 +++++++++ 13 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/es3-jsx-preserve.js create mode 100644 tests/baselines/reference/es3-jsx-preserve.symbols create mode 100644 tests/baselines/reference/es3-jsx-preserve.types create mode 100644 tests/baselines/reference/es3-jsx-react-native.js create mode 100644 tests/baselines/reference/es3-jsx-react-native.symbols create mode 100644 tests/baselines/reference/es3-jsx-react-native.types create mode 100644 tests/baselines/reference/es3-jsx-react.js create mode 100644 tests/baselines/reference/es3-jsx-react.symbols create mode 100644 tests/baselines/reference/es3-jsx-react.types create mode 100644 tests/cases/compiler/es3-jsx-preserve.tsx create mode 100644 tests/cases/compiler/es3-jsx-react-native.tsx create mode 100644 tests/cases/compiler/es3-jsx-react.tsx diff --git a/src/compiler/transformers/es5.ts b/src/compiler/transformers/es5.ts index 6dd875965d96d..972b9214f16fd 100644 --- a/src/compiler/transformers/es5.ts +++ b/src/compiler/transformers/es5.ts @@ -14,7 +14,7 @@ namespace ts { // enable emit notification only if using --jsx preserve let previousOnEmitNode: (emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void) => void; let noSubstitution: boolean[]; - if (compilerOptions.jsx === JsxEmit.Preserve) { + if (compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) { previousOnEmitNode = context.onEmitNode; context.onEmitNode = onEmitNode; context.enableEmitNotification(SyntaxKind.JsxOpeningElement); @@ -116,4 +116,4 @@ namespace ts { return undefined; } } -} \ No newline at end of file +} diff --git a/tests/baselines/reference/es3-jsx-preserve.js b/tests/baselines/reference/es3-jsx-preserve.js new file mode 100644 index 0000000000000..cb1ba2a887dd8 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-preserve.js @@ -0,0 +1,11 @@ +//// [es3-jsx-preserve.tsx] + +const React: any = null; + +const elem =
; + + + +//// [es3-jsx-preserve.jsx] +var React = null; +var elem =
; diff --git a/tests/baselines/reference/es3-jsx-preserve.symbols b/tests/baselines/reference/es3-jsx-preserve.symbols new file mode 100644 index 0000000000000..61c9260223fd4 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-preserve.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/es3-jsx-preserve.tsx === + +const React: any = null; +>React : Symbol(React, Decl(es3-jsx-preserve.tsx, 1, 5)) + +const elem =
; +>elem : Symbol(elem, Decl(es3-jsx-preserve.tsx, 3, 5)) +>div : Symbol(unknown) +>div : Symbol(unknown) + + diff --git a/tests/baselines/reference/es3-jsx-preserve.types b/tests/baselines/reference/es3-jsx-preserve.types new file mode 100644 index 0000000000000..b37fe8af56738 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-preserve.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/es3-jsx-preserve.tsx === + +const React: any = null; +>React : any +>null : null + +const elem =
; +>elem : any +>
: any +>div : any +>div : any + + diff --git a/tests/baselines/reference/es3-jsx-react-native.js b/tests/baselines/reference/es3-jsx-react-native.js new file mode 100644 index 0000000000000..08e6e25502b70 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react-native.js @@ -0,0 +1,11 @@ +//// [es3-jsx-react-native.tsx] + +const React: any = null; + +const elem =
; + + + +//// [es3-jsx-react-native.js] +var React = null; +var elem =
; diff --git a/tests/baselines/reference/es3-jsx-react-native.symbols b/tests/baselines/reference/es3-jsx-react-native.symbols new file mode 100644 index 0000000000000..e7f010bd2ead0 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react-native.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/es3-jsx-react-native.tsx === + +const React: any = null; +>React : Symbol(React, Decl(es3-jsx-react-native.tsx, 1, 5)) + +const elem =
; +>elem : Symbol(elem, Decl(es3-jsx-react-native.tsx, 3, 5)) +>div : Symbol(unknown) +>div : Symbol(unknown) + + diff --git a/tests/baselines/reference/es3-jsx-react-native.types b/tests/baselines/reference/es3-jsx-react-native.types new file mode 100644 index 0000000000000..1bf199606f299 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react-native.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/es3-jsx-react-native.tsx === + +const React: any = null; +>React : any +>null : null + +const elem =
; +>elem : any +>
: any +>div : any +>div : any + + diff --git a/tests/baselines/reference/es3-jsx-react.js b/tests/baselines/reference/es3-jsx-react.js new file mode 100644 index 0000000000000..861dde74c86e4 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react.js @@ -0,0 +1,11 @@ +//// [es3-jsx-react.tsx] + +const React: any = null; + +const elem =
; + + + +//// [es3-jsx-react.js] +var React = null; +var elem = React.createElement("div", null); diff --git a/tests/baselines/reference/es3-jsx-react.symbols b/tests/baselines/reference/es3-jsx-react.symbols new file mode 100644 index 0000000000000..465cfab7ea901 --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/es3-jsx-react.tsx === + +const React: any = null; +>React : Symbol(React, Decl(es3-jsx-react.tsx, 1, 5)) + +const elem =
; +>elem : Symbol(elem, Decl(es3-jsx-react.tsx, 3, 5)) +>div : Symbol(unknown) +>div : Symbol(unknown) + + diff --git a/tests/baselines/reference/es3-jsx-react.types b/tests/baselines/reference/es3-jsx-react.types new file mode 100644 index 0000000000000..b7734ffc1f0db --- /dev/null +++ b/tests/baselines/reference/es3-jsx-react.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/es3-jsx-react.tsx === + +const React: any = null; +>React : any +>null : null + +const elem =
; +>elem : any +>
: any +>div : any +>div : any + + diff --git a/tests/cases/compiler/es3-jsx-preserve.tsx b/tests/cases/compiler/es3-jsx-preserve.tsx new file mode 100644 index 0000000000000..f6092e692b496 --- /dev/null +++ b/tests/cases/compiler/es3-jsx-preserve.tsx @@ -0,0 +1,9 @@ +// @target: ES3 +// @sourcemap: false +// @declaration: false +// @jsx: preserve + +const React: any = null; + +const elem =
; + diff --git a/tests/cases/compiler/es3-jsx-react-native.tsx b/tests/cases/compiler/es3-jsx-react-native.tsx new file mode 100644 index 0000000000000..9ed0f9e003d3b --- /dev/null +++ b/tests/cases/compiler/es3-jsx-react-native.tsx @@ -0,0 +1,9 @@ +// @target: ES3 +// @sourcemap: false +// @declaration: false +// @jsx: react-native + +const React: any = null; + +const elem =
; + diff --git a/tests/cases/compiler/es3-jsx-react.tsx b/tests/cases/compiler/es3-jsx-react.tsx new file mode 100644 index 0000000000000..d47aea9613f26 --- /dev/null +++ b/tests/cases/compiler/es3-jsx-react.tsx @@ -0,0 +1,9 @@ +// @target: ES3 +// @sourcemap: false +// @declaration: false +// @jsx: react + +const React: any = null; + +const elem =
; + From 6fda5a1b3a3018623e3b3d49ab9520a9af24510c Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Mon, 23 Jan 2017 22:14:51 +0100 Subject: [PATCH 5/7] Update comment about jsx react-native in es5.ts --- src/compiler/transformers/es5.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/transformers/es5.ts b/src/compiler/transformers/es5.ts index 972b9214f16fd..c3b011fe36d47 100644 --- a/src/compiler/transformers/es5.ts +++ b/src/compiler/transformers/es5.ts @@ -11,7 +11,7 @@ namespace ts { export function transformES5(context: TransformationContext) { const compilerOptions = context.getCompilerOptions(); - // enable emit notification only if using --jsx preserve + // enable emit notification only if using --jsx preserve or react-native let previousOnEmitNode: (emitContext: EmitContext, node: Node, emitCallback: (emitContext: EmitContext, node: Node) => void) => void; let noSubstitution: boolean[]; if (compilerOptions.jsx === JsxEmit.Preserve || compilerOptions.jsx === JsxEmit.ReactNative) { From ebb666a9c2e01a5ae1358252e0dde6a3e83f11f1 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Tue, 24 Jan 2017 05:09:30 +0100 Subject: [PATCH 6/7] delete fourslash testcase for --jsx react-native --- .../getEmitOutputTsxFile_ReactNative.baseline | 26 ------------------- .../getEmitOutputTsxFile_ReactNative.ts | 22 ---------------- 2 files changed, 48 deletions(-) delete mode 100644 tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline delete mode 100644 tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts diff --git a/tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline b/tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline deleted file mode 100644 index 88fb0f0daf6a8..0000000000000 --- a/tests/baselines/reference/getEmitOutputTsxFile_ReactNative.baseline +++ /dev/null @@ -1,26 +0,0 @@ -EmitSkipped: false -FileName : /tests/cases/fourslash/inputFile1.js.map -{"version":3,"file":"inputFile1.js","sourceRoot":"","sources":["inputFile1.ts"],"names":[],"mappings":"AAAA,kBAAkB;AACjB,IAAI,CAAC,GAAW,CAAC,CAAC;AAClB;IAAA;IAGA,CAAC;IAAD,UAAC;AAAD,CAAC,AAHD,IAGC"}FileName : /tests/cases/fourslash/inputFile1.js -// regular ts file -var t = 5; -var Bar = (function () { - function Bar() { - } - return Bar; -}()); -//# sourceMappingURL=inputFile1.js.mapFileName : /tests/cases/fourslash/inputFile1.d.ts -declare var t: number; -declare class Bar { - x: string; - y: number; -} - -EmitSkipped: false -FileName : /tests/cases/fourslash/inputFile2.js.map -{"version":3,"file":"inputFile2.js","sourceRoot":"","sources":["inputFile2.tsx"],"names":[],"mappings":"AAAA,IAAI,CAAC,GAAG,QAAQ,CAAC;AACjB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,EAAG,CAAA"}FileName : /tests/cases/fourslash/inputFile2.js -var y = "my div"; -var x =
; -//# sourceMappingURL=inputFile2.js.mapFileName : /tests/cases/fourslash/inputFile2.d.ts -declare var y: string; -declare var x: any; - diff --git a/tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts b/tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts deleted file mode 100644 index c2aac0e9d0398..0000000000000 --- a/tests/cases/fourslash/getEmitOutputTsxFile_ReactNative.ts +++ /dev/null @@ -1,22 +0,0 @@ -/// - -// @BaselineFile: getEmitOutputTsxFile_ReactNative.baseline -// @declaration: true -// @sourceMap: true -// @jsx: react-native - -// @Filename: inputFile1.ts -// @emitThisFile: true -////// regular ts file -//// var t: number = 5; -//// class Bar { -//// x : string; -//// y : number -//// } - -// @Filename: inputFile2.tsx -// @emitThisFile: true -//// var y = "my div"; -//// var x =
- -verify.baselineGetEmitOutput(); From 0a4632fe79c0390db616812ee9a5d2dd1fc1cff6 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Tue, 24 Jan 2017 07:16:15 +0100 Subject: [PATCH 7/7] revert change to lib/protocol.d.ts --- lib/protocol.d.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index cd46ebcd36612..d6c0246af34c9 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1798,10 +1798,9 @@ declare namespace ts.server.protocol { namespace JsxEmit { type None = "None"; type Preserve = "Preserve"; - type ReactNative = "ReactNative"; type React = "React"; } - type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React | JsxEmit.ReactNative; + type JsxEmit = JsxEmit.None | JsxEmit.Preserve | JsxEmit.React; namespace ModuleKind { type None = "None"; type CommonJS = "CommonJS"; @@ -1881,4 +1880,4 @@ declare namespace ts { } import protocol = ts.server.protocol; export = protocol; -export as namespace protocol; +export as namespace protocol; \ No newline at end of file