Skip to content

Commit 7e46ba0

Browse files
committed
RFC: <script type="ts/module">
1 parent c87bce1 commit 7e46ba0

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

hello-world.ts.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html>
2+
<title>node built/local/tsc.js --html hello-world.ts.html</title>
3+
<body>
4+
<template>
5+
<style>
6+
:host {
7+
display: block;
8+
box-sizing: border-box;
9+
border: 1px solid red;
10+
margin-top: 10px;
11+
padding: 0px 5px;
12+
}
13+
</style>
14+
<p>Test <slot></slot></p>
15+
</template>
16+
<script type="ts/module">
17+
class HelloWorld extends HTMLElement {
18+
_hello: string = "Hello World"
19+
constructor() {
20+
super()
21+
const t = document.querySelector('template')
22+
if (t == null) return;
23+
const instance = t.content.cloneNode(true)
24+
const shadowRoot = this.attachShadow({ mode: 'open' })
25+
shadowRoot.appendChild(instance)
26+
}
27+
}
28+
customElements.define('hello-world', HelloWorld);
29+
</script>
30+
<hello-world>Hello World</hello-world>
31+
</body>
32+
</html>

src/compiler/commandLineParser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace ts {
5050
shortName: "?",
5151
type: "boolean"
5252
},
53+
{
54+
name: "html",
55+
type: "boolean"
56+
// TODO
57+
// description: "<script type=\"ts/module\">...</script>"
58+
},
5359
{
5460
name: "init",
5561
type: "boolean",

src/compiler/core.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,8 @@ namespace ts {
18981898
return ScriptKind.TS;
18991899
case ".tsx":
19001900
return ScriptKind.TSX;
1901+
case ".html":
1902+
return ScriptKind.HTML;
19011903
default:
19021904
return ScriptKind.Unknown;
19031905
}
@@ -1906,9 +1908,9 @@ namespace ts {
19061908
/**
19071909
* List of supported extensions in order of file resolution precedence.
19081910
*/
1909-
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
1911+
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".ts.html", ".d.ts"];
19101912
/** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */
1911-
export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts", ".tsx"];
1913+
export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts.html", ".ts", ".tsx"];
19121914
export const supportedJavascriptExtensions = [".js", ".jsx"];
19131915
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);
19141916

@@ -1988,7 +1990,7 @@ namespace ts {
19881990
}
19891991
}
19901992

1991-
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
1993+
const extensionsToRemove = [".d.ts", ".ts.html", ".ts", ".js", ".tsx", ".jsx"];
19921994
export function removeFileExtension(path: string): string {
19931995
for (const ext of extensionsToRemove) {
19941996
const extensionless = tryRemoveExtension(path, ext);
@@ -2213,6 +2215,9 @@ namespace ts {
22132215
if (fileExtensionIs(path, ".d.ts")) {
22142216
return Extension.Dts;
22152217
}
2218+
if (fileExtensionIs(path, ".ts.html")) {
2219+
return Extension.tsHTML;
2220+
}
22162221
if (fileExtensionIs(path, ".ts")) {
22172222
return Extension.Ts;
22182223
}

src/compiler/program.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,11 @@ namespace ts {
16731673
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
16741674
}
16751675

1676+
if (options.html) {
1677+
// TODO
1678+
// programDiagnostics.add(createCompilerDiagnostic(Diagnostics..., "HTML"));
1679+
}
1680+
16761681
if (options.jsxFactory) {
16771682
if (options.reactNamespace) {
16781683
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory"));

src/compiler/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,7 @@ namespace ts {
30593059
experimentalDecorators?: boolean;
30603060
forceConsistentCasingInFileNames?: boolean;
30613061
/*@internal*/help?: boolean;
3062+
html?: boolean;
30623063
importHelpers?: boolean;
30633064
/*@internal*/init?: boolean;
30643065
inlineSourceMap?: boolean;
@@ -3170,7 +3171,8 @@ namespace ts {
31703171
JS = 1,
31713172
JSX = 2,
31723173
TS = 3,
3173-
TSX = 4
3174+
TSX = 4,
3175+
HTML = 5
31743176
}
31753177

31763178
export const enum ScriptTarget {
@@ -3434,6 +3436,7 @@ namespace ts {
34343436
export enum Extension {
34353437
Ts,
34363438
Tsx,
3439+
tsHTML,
34373440
Dts,
34383441
Js,
34393442
Jsx,

0 commit comments

Comments
 (0)