@@ -5,12 +5,49 @@ import { grammars, injections } from 'tm-grammars'
5
5
import { COMMENT_HEAD } from './constants'
6
6
7
7
/**
8
- * Languages that includes a lot of embedded langs,
9
- * We only load on-demand for these langs.
8
+ * Document-like languages that have embedded langs
10
9
*/
11
- const LANGS_LAZY_EMBEDDED = [
10
+ const LANGS_LAZY_EMBEDDED_ALL = {
11
+ markdown : [ ] ,
12
+ mdx : [ ] ,
13
+ wikitext : [ ] ,
14
+ asciidoc : [ ] ,
15
+ latex : [ 'tex' ] ,
16
+ } as Record < string , string [ ] >
17
+
18
+ /**
19
+ * Single-file-component-like languages that have embedded langs
20
+ * For these langs, we exclude the standalone embedded langs from the main bundle
21
+ */
22
+ const LANGS_LAZY_EMBEDDED_PARTIAL = [
23
+ 'vue' ,
24
+ 'vue-html' ,
25
+ 'svelte' ,
26
+ 'pug' ,
27
+ 'haml' ,
28
+ 'astro' ,
29
+ ]
30
+
31
+ /**
32
+ * Languages to be excluded from SFC langs
33
+ */
34
+ const STANDALONG_LANGS_EMBEDDED = [
35
+ 'pug' ,
36
+ 'stylus' ,
37
+ 'sass' ,
38
+ 'scss' ,
39
+ 'coffee' ,
40
+ 'jsonc' ,
41
+ 'json5' ,
42
+ 'yaml' ,
43
+ 'toml' ,
44
+ 'scss' ,
45
+ 'graphql' ,
12
46
'markdown' ,
13
- 'mdx' ,
47
+ 'less' ,
48
+ 'jsx' ,
49
+ 'tsx' ,
50
+ 'ruby' ,
14
51
]
15
52
16
53
export async function prepareLangs ( ) {
@@ -22,6 +59,8 @@ export async function prepareLangs() {
22
59
23
60
allLangFiles . sort ( )
24
61
62
+ const resolvedLangs : LanguageRegistration [ ] = [ ]
63
+
25
64
for ( const file of allLangFiles ) {
26
65
const content = await fs . readJSON ( file )
27
66
const lang = grammars . find ( i => i . name === content . name ) || injections . find ( i => i . name === content . name )
@@ -40,12 +79,21 @@ export async function prepareLangs() {
40
79
}
41
80
42
81
// We don't load all the embedded langs for markdown
43
- if ( LANGS_LAZY_EMBEDDED . includes ( lang . name ) ) {
44
- json . embeddedLangsLazy = json . embeddedLangs
45
- json . embeddedLangs = [ ]
82
+ if ( LANGS_LAZY_EMBEDDED_ALL [ lang . name ] ) {
83
+ const includes = LANGS_LAZY_EMBEDDED_ALL [ lang . name ]
84
+ json . embeddedLangsLazy = ( json . embeddedLangs || [ ] ) . filter ( i => ! includes . includes ( i ) ) || [ ]
85
+ json . embeddedLangs = includes
86
+ }
87
+ else if ( LANGS_LAZY_EMBEDDED_PARTIAL . includes ( lang . name ) ) {
88
+ json . embeddedLangsLazy = ( json . embeddedLangs || [ ] ) . filter ( i => STANDALONG_LANGS_EMBEDDED . includes ( i ) ) || [ ]
89
+ json . embeddedLangs = ( json . embeddedLangs || [ ] ) . filter ( i => ! STANDALONG_LANGS_EMBEDDED . includes ( i ) ) || [ ]
46
90
}
47
91
48
92
const deps : string [ ] = json . embeddedLangs || [ ]
93
+ resolvedLangs . push ( json )
94
+
95
+ if ( deps . length > 10 )
96
+ console . log ( json . name , json . embeddedLangs )
49
97
50
98
await fs . writeFile (
51
99
`./src/assets/langs/${ lang . name } .js` ,
@@ -102,12 +150,10 @@ export default langs
102
150
while ( changed ) {
103
151
changed = false
104
152
for ( const id of bundledIds ) {
105
- if ( LANGS_LAZY_EMBEDDED . includes ( id ) )
106
- continue
107
- const lang = grammars . find ( i => i . name === id )
153
+ const lang = resolvedLangs . find ( i => i . name === id )
108
154
if ( ! lang )
109
155
continue
110
- for ( const e of lang . embedded || [ ] ) {
156
+ for ( const e of lang . embeddedLangs || [ ] ) {
111
157
if ( ! bundledIds . has ( e ) ) {
112
158
bundledIds . add ( e )
113
159
changed = true
0 commit comments