File tree Expand file tree Collapse file tree 5 files changed +26
-9
lines changed Expand file tree Collapse file tree 5 files changed +26
-9
lines changed Original file line number Diff line number Diff line change 113
113
The `type` attribute can have one of the following values:
114
114
115
115
- `module` - JavaScript
116
+ - `text/x-typescript` - TypeScript
116
117
- `text/markdown` - Markdown
117
118
- `text/html` - HTML
118
119
- `application/sql` - SQL
131
132
<\/script>
132
133
` ``
133
134
</ script >
135
+ < script id ="86 " type ="text/markdown ">
136
+ A TypeScript ( `text/x-typescript` ) cell:
137
+
138
+ `` `html
139
+ <script type="text/x-typescript">
140
+ let hello: string = "hello";
141
+ <\/script>
142
+ ` ``
143
+ </ script >
134
144
< script id ="52 " type ="text/markdown ">
135
145
A Markdown ( `text/markdown` ) cell:
136
146
Original file line number Diff line number Diff line change 61
61
"jsdom" : " ^26.1.0" ,
62
62
"markdown-it" : " ^14.1.0" ,
63
63
"markdown-it-anchor" : " ^9.2.0" ,
64
+ "typescript" : " ^5.8.3" ,
64
65
"vite" : " ^7.0.0"
65
66
},
66
67
"devDependencies" : {
77
78
"postgres" : " ^3.4.7" ,
78
79
"snowflake-sdk" : " ^2.1.3" ,
79
80
"tsx" : " ^4.20.3" ,
80
- "typescript" : " ^5.8.3" ,
81
81
"typescript-eslint" : " ^8.35.0" ,
82
82
"vitest" : " ^3.2.4"
83
83
},
Original file line number Diff line number Diff line change
1
+ import { ScriptTarget , transpile as transpileTypeScript } from "typescript" ;
1
2
import type { Cell } from "../lib/notebook.js" ;
2
3
import { toCell } from "../lib/notebook.js" ;
3
4
import { rewriteFileExpressions } from "./files.js" ;
@@ -55,14 +56,16 @@ export function transpile(
55
56
input = cell . value ;
56
57
}
57
58
const transpiled =
58
- mode === "ojs"
59
- ? transpileObservable ( input , options )
60
- : mode !== "js"
61
- ? transpileJavaScript ( transpileTemplate ( cell ) , options )
62
- : transpileJavaScript ( input , options ) ;
59
+ mode === "ts"
60
+ ? transpileJavaScript ( transpileTypeScript ( input , { target : ScriptTarget . ESNext } ) , options )
61
+ : mode === "ojs"
62
+ ? transpileObservable ( input , options )
63
+ : mode !== "js"
64
+ ? transpileJavaScript ( transpileTemplate ( cell ) , options )
65
+ : transpileJavaScript ( input , options ) ;
63
66
if ( transpiled . output === undefined ) transpiled . output = cell . output ;
64
67
if ( cell . hidden ) transpiled . autodisplay = false ;
65
- else if ( mode !== "js" && mode !== "ojs" ) {
68
+ else if ( mode !== "js" && mode !== "ts" && mode !== " ojs") {
66
69
transpiled . autodisplay = ! ! input ;
67
70
transpiled . autoview = mode === "sql" && transpiled . autodisplay && ! ! transpiled . output ;
68
71
if ( transpiled . autoview ) transpiled . output = `viewof$${ transpiled . output } ` ;
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export interface CellSpec {
39
39
/** the committed cell value; defaults to empty */
40
40
value ?: string ;
41
41
/** the mode; affects how the value is evaluated; defaults to js */
42
- mode ?: "js" | "ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python" ;
42
+ mode ?: "js" | "ts" | " ojs" | "md" | "html" | "tex" | "dot" | "sql" | "node" | "python" ;
43
43
/** if true, the editor will stay open when not focused; defaults to false */
44
44
pinned ?: boolean ;
45
45
/** if true, implicit display will be suppressed; defaults to false */
@@ -120,5 +120,5 @@ function asDate(date: Date | string | number): Date {
120
120
}
121
121
122
122
export function defaultPinned ( mode : Cell [ "mode" ] ) : boolean {
123
- return mode === "js" || mode === "sql" || isInterpreter ( mode ) || mode === "ojs" ;
123
+ return mode === "js" || mode === "ts" || mode === " sql" || isInterpreter ( mode ) || mode === "ojs" ;
124
124
}
Original file line number Diff line number Diff line change @@ -73,6 +73,8 @@ function serializeMode(mode: Cell["mode"]): string {
73
73
return "text/x-python" ;
74
74
case "ojs" :
75
75
return "application/vnd.observable.javascript" ;
76
+ case "ts" :
77
+ return "text/x-typescript" ;
76
78
default :
77
79
return "module" ;
78
80
}
@@ -96,6 +98,8 @@ function deserializeMode(mode: string | null): Cell["mode"] {
96
98
return "python" ;
97
99
case "application/vnd.observable.javascript" :
98
100
return "ojs" ;
101
+ case "text/x-typescript" :
102
+ return "ts" ;
99
103
default :
100
104
return "js" ;
101
105
}
You can’t perform that action at this time.
0 commit comments