Skip to content

Commit

Permalink
RFC: <script type="ts/module">
Browse files Browse the repository at this point in the history
  • Loading branch information
gertcuykens committed Nov 12, 2016
1 parent c87bce1 commit 7e46ba0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
32 changes: 32 additions & 0 deletions hello-world.ts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html>
<title>node built/local/tsc.js --html hello-world.ts.html</title>
<body>
<template>
<style>
:host {
display: block;
box-sizing: border-box;
border: 1px solid red;
margin-top: 10px;
padding: 0px 5px;
}
</style>
<p>Test <slot></slot></p>
</template>
<script type="ts/module">
class HelloWorld extends HTMLElement {
_hello: string = "Hello World"
constructor() {
super()
const t = document.querySelector('template')
if (t == null) return;
const instance = t.content.cloneNode(true)
const shadowRoot = this.attachShadow({ mode: 'open' })
shadowRoot.appendChild(instance)
}
}
customElements.define('hello-world', HelloWorld);
</script>
<hello-world>Hello World</hello-world>
</body>
</html>
6 changes: 6 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ namespace ts {
shortName: "?",
type: "boolean"
},
{
name: "html",
type: "boolean"
// TODO
// description: "<script type=\"ts/module\">...</script>"
},
{
name: "init",
type: "boolean",
Expand Down
11 changes: 8 additions & 3 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,8 @@ namespace ts {
return ScriptKind.TS;
case ".tsx":
return ScriptKind.TSX;
case ".html":
return ScriptKind.HTML;
default:
return ScriptKind.Unknown;
}
Expand All @@ -1906,9 +1908,9 @@ namespace ts {
/**
* List of supported extensions in order of file resolution precedence.
*/
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".d.ts"];
export const supportedTypeScriptExtensions = [".ts", ".tsx", ".ts.html", ".d.ts"];
/** Must have ".d.ts" first because if ".ts" goes first, that will be detected as the extension instead of ".d.ts". */
export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts", ".tsx"];
export const supportedTypescriptExtensionsForExtractExtension = [".d.ts", ".ts.html", ".ts", ".tsx"];
export const supportedJavascriptExtensions = [".js", ".jsx"];
const allSupportedExtensions = supportedTypeScriptExtensions.concat(supportedJavascriptExtensions);

Expand Down Expand Up @@ -1988,7 +1990,7 @@ namespace ts {
}
}

const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
const extensionsToRemove = [".d.ts", ".ts.html", ".ts", ".js", ".tsx", ".jsx"];
export function removeFileExtension(path: string): string {
for (const ext of extensionsToRemove) {
const extensionless = tryRemoveExtension(path, ext);
Expand Down Expand Up @@ -2213,6 +2215,9 @@ namespace ts {
if (fileExtensionIs(path, ".d.ts")) {
return Extension.Dts;
}
if (fileExtensionIs(path, ".ts.html")) {
return Extension.tsHTML;
}
if (fileExtensionIs(path, ".ts")) {
return Extension.Ts;
}
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,11 @@ namespace ts {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators"));
}

if (options.html) {
// TODO
// programDiagnostics.add(createCompilerDiagnostic(Diagnostics..., "HTML"));
}

if (options.jsxFactory) {
if (options.reactNamespace) {
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "reactNamespace", "jsxFactory"));
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3059,6 +3059,7 @@ namespace ts {
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
/*@internal*/help?: boolean;
html?: boolean;
importHelpers?: boolean;
/*@internal*/init?: boolean;
inlineSourceMap?: boolean;
Expand Down Expand Up @@ -3170,7 +3171,8 @@ namespace ts {
JS = 1,
JSX = 2,
TS = 3,
TSX = 4
TSX = 4,
HTML = 5
}

export const enum ScriptTarget {
Expand Down Expand Up @@ -3434,6 +3436,7 @@ namespace ts {
export enum Extension {
Ts,
Tsx,
tsHTML,
Dts,
Js,
Jsx,
Expand Down

0 comments on commit 7e46ba0

Please sign in to comment.