File tree Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Expand file tree Collapse file tree 4 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -1695,4 +1695,19 @@ describe('compileScript', () => {
16951695 )
16961696 assertCode ( content )
16971697 } )
1698+
1699+ test ( 'should not compile unrecognized language' , ( ) => {
1700+ const { content, lang, scriptAst } = compile (
1701+ `<script lang="coffee">
1702+ export default
1703+ data: ->
1704+ myVal: 0
1705+ </script>` ,
1706+ )
1707+ expect ( content ) . toMatch ( `export default
1708+ data: ->
1709+ myVal: 0` )
1710+ expect ( lang ) . toBe ( 'coffee' )
1711+ expect ( scriptAst ) . not . toBeDefined ( )
1712+ } )
16981713} )
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import type { BindingMetadata } from '../../../compiler-core/src'
99import MagicString from 'magic-string'
1010import type { TypeScope } from './resolveType'
1111import { warn } from '../warn'
12+ import { isJS , isTS } from './utils'
1213
1314export class ScriptCompileContext {
1415 isJS : boolean
@@ -87,16 +88,8 @@ export class ScriptCompileContext {
8788 const scriptLang = script && script . lang
8889 const scriptSetupLang = scriptSetup && scriptSetup . lang
8990
90- this . isJS =
91- scriptLang === 'js' ||
92- scriptLang === 'jsx' ||
93- scriptSetupLang === 'js' ||
94- scriptSetupLang === 'jsx'
95- this . isTS =
96- scriptLang === 'ts' ||
97- scriptLang === 'tsx' ||
98- scriptSetupLang === 'ts' ||
99- scriptSetupLang === 'tsx'
91+ this . isJS = isJS ( scriptLang , scriptSetupLang )
92+ this . isTS = isTS ( scriptLang , scriptSetupLang )
10093
10194 const customElement = options . customElement
10295 const filename = this . descriptor . filename
Original file line number Diff line number Diff line change @@ -12,10 +12,6 @@ export function processNormalScript(
1212 scopeId : string ,
1313) : SFCScriptBlock {
1414 const script = ctx . descriptor . script !
15- if ( script . lang && ! ctx . isJS && ! ctx . isTS ) {
16- // do not process non js/ts script blocks
17- return script
18- }
1915 try {
2016 let content = script . content
2117 let map = script . map
Original file line number Diff line number Diff line change @@ -121,3 +121,8 @@ export const propNameEscapeSymbolsRE: RegExp =
121121export function getEscapedPropName ( key : string ) : string {
122122 return propNameEscapeSymbolsRE . test ( key ) ? JSON . stringify ( key ) : key
123123}
124+
125+ export const isJS = ( ...langs : ( string | null | undefined ) [ ] ) : boolean =>
126+ langs . some ( lang => lang === 'js' || lang === 'jsx' )
127+ export const isTS = ( ...langs : ( string | null | undefined ) [ ] ) : boolean =>
128+ langs . some ( lang => lang === 'ts' || lang === 'tsx' )
You can’t perform that action at this time.
0 commit comments