Skip to content

Commit 7f367d2

Browse files
committed
chore(compiler): Update Babel 8
Update Babel from v7 to v8 BREAKING CHANGE: Node types updated to Babel v8 definitions.
1 parent 5a8aa0b commit 7f367d2

File tree

16 files changed

+254
-154
lines changed

16 files changed

+254
-154
lines changed

packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ describe('compiler: expression transform', () => {
592592
[
593593
'pipelineOperator',
594594
{
595-
proposal: 'minimal',
595+
proposal: 'fsharp',
596596
},
597597
],
598598
],

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,20 +1358,6 @@ _sfc_.setup = __setup__
13581358
"
13591359
`;
13601360
1361-
exports[`SFC genDefaultAs > parser plugins > import attributes (user override for deprecated syntax) 1`] = `
1362-
"import { foo } from './foo.js' assert { type: 'foobar' }
1363-
1364-
export default {
1365-
setup(__props, { expose: __expose }) {
1366-
__expose();
1367-
1368-
1369-
return { get foo() { return foo } }
1370-
}
1371-
1372-
}"
1373-
`;
1374-
13751361
exports[`SFC genDefaultAs > parser plugins > import attributes 1`] = `
13761362
"import { foo } from './foo.js' with { type: 'foobar' }
13771363

packages/compiler-sfc/__tests__/compileScript.spec.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,22 +1510,6 @@ describe('SFC genDefaultAs', () => {
15101510
</script>`),
15111511
).toThrow()
15121512
})
1513-
1514-
test('import attributes (user override for deprecated syntax)', () => {
1515-
const { content } = compile(
1516-
`
1517-
<script setup>
1518-
import { foo } from './foo.js' assert { type: 'foobar' }
1519-
</script>
1520-
`,
1521-
{
1522-
babelParserPlugins: [
1523-
['importAttributes', { deprecatedAssertSyntax: true }],
1524-
],
1525-
},
1526-
)
1527-
assertCode(content)
1528-
})
15291513
})
15301514
})
15311515

packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,7 @@ function resolve(
16531653
s.expression.type === 'CallExpression' &&
16541654
(s.expression.callee as Identifier).name === 'defineProps'
16551655
) {
1656-
target = s.expression.typeParameters!.params[0]
1656+
target = s.expression.typeArguments!.params[0]
16571657
}
16581658
}
16591659
const raw = resolveTypeElements(ctx, target)

packages/compiler-sfc/__tests__/utils.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ export function assertCode(code: string): void {
2929
try {
3030
babelParse(code, {
3131
sourceType: 'module',
32-
plugins: [
33-
'typescript',
34-
['importAttributes', { deprecatedAssertSyntax: true }],
35-
],
32+
plugins: ['typescript'],
3633
})
3734
} catch (e: any) {
3835
console.log(code)

packages/compiler-sfc/src/compileScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ function walkDeclaration(
11611161
}
11621162
}
11631163
} else if (node.type === 'TSEnumDeclaration') {
1164-
isAllLiteral = node.members.every(
1164+
isAllLiteral = node.body.members.every(
11651165
member => !member.initializer || isStaticNode(member.initializer),
11661166
)
11671167
bindings[node.id!.name] = isAllLiteral

packages/compiler-sfc/src/script/context.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { CallExpression, Node, ObjectPattern, Program } from '@babel/types'
22
import type { SFCDescriptor } from '../parse'
3-
import { generateCodeFrame, isArray } from '@vue/shared'
3+
import { generateCodeFrame } from '@vue/shared'
44
import { type ParserPlugin, parse as babelParse } from '@babel/parser'
55
import type { ImportBinding, SFCScriptCompileOptions } from '../compileScript'
66
import type { PropsDestructureBindings } from './defineProps'
@@ -170,17 +170,6 @@ export function resolveParserPlugins(
170170
dts = false,
171171
): ParserPlugin[] {
172172
const plugins: ParserPlugin[] = []
173-
if (
174-
!userPlugins ||
175-
!userPlugins.some(
176-
p =>
177-
p === 'importAssertions' ||
178-
p === 'importAttributes' ||
179-
(isArray(p) && p[0] === 'importAttributes'),
180-
)
181-
) {
182-
plugins.push('importAttributes')
183-
}
184173
if (lang === 'jsx' || lang === 'tsx' || lang === 'mtsx') {
185174
plugins.push('jsx')
186175
} else if (userPlugins) {
@@ -189,7 +178,7 @@ export function resolveParserPlugins(
189178
userPlugins = userPlugins.filter(p => p !== 'jsx')
190179
}
191180
if (lang === 'ts' || lang === 'mts' || lang === 'tsx' || lang === 'mtsx') {
192-
plugins.push(['typescript', { dts }], 'explicitResourceManagement')
181+
plugins.push(['typescript', { dts }])
193182
if (!userPlugins || !userPlugins.includes('decorators')) {
194183
plugins.push('decorators-legacy')
195184
}

packages/compiler-sfc/src/script/defineEmits.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ export function processDefineEmits(
2929
}
3030
ctx.hasDefineEmitCall = true
3131
ctx.emitsRuntimeDecl = node.arguments[0]
32-
if (node.typeParameters) {
32+
if (node.typeArguments) {
3333
if (ctx.emitsRuntimeDecl) {
3434
ctx.error(
3535
`${DEFINE_EMITS}() cannot accept both type and non-type arguments ` +
3636
`at the same time. Use one or the other.`,
3737
node,
3838
)
3939
}
40-
ctx.emitsTypeDecl = node.typeParameters.params[0]
40+
ctx.emitsTypeDecl = node.typeArguments.params[0]
4141
}
4242

4343
ctx.emitDecl = declId
@@ -75,7 +75,7 @@ export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
7575
const node = ctx.emitsTypeDecl!
7676

7777
if (node.type === 'TSFunctionType') {
78-
extractEventNames(ctx, node.parameters[0], emits)
78+
extractEventNames(ctx, node.params[0], emits)
7979
return emits
8080
}
8181

@@ -95,7 +95,7 @@ export function extractRuntimeEmits(ctx: TypeResolveContext): Set<string> {
9595
)
9696
}
9797
for (const call of calls) {
98-
extractEventNames(ctx, call.parameters[0], emits)
98+
extractEventNames(ctx, call.params[0], emits)
9999
}
100100
}
101101

packages/compiler-sfc/src/script/defineModel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ export function processDefineModel(
2424

2525
ctx.hasDefineModelCall = true
2626

27-
const type =
28-
(node.typeParameters && node.typeParameters.params[0]) || undefined
27+
const type = (node.typeArguments && node.typeArguments.params[0]) as
28+
| TSType
29+
| undefined
2930
let modelName: string
3031
let options: Node | undefined
3132
const arg0 = node.arguments[0] && unwrapTSNode(node.arguments[0])

packages/compiler-sfc/src/script/defineOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function processDefineOptions(
1919
if (ctx.hasDefineOptionsCall) {
2020
ctx.error(`duplicate ${DEFINE_OPTIONS}() call`, node)
2121
}
22-
if (node.typeParameters) {
22+
if (node.typeArguments) {
2323
ctx.error(`${DEFINE_OPTIONS}() cannot accept type arguments`, node)
2424
}
2525
if (!node.arguments[0]) return true

0 commit comments

Comments
 (0)