diff --git a/packages/plugin-legacy/src/__tests__/snippets.spec.ts b/packages/plugin-legacy/src/__tests__/snippets.spec.ts index 65376ef102d023..0b2812a991c5e1 100644 --- a/packages/plugin-legacy/src/__tests__/snippets.spec.ts +++ b/packages/plugin-legacy/src/__tests__/snippets.spec.ts @@ -1,15 +1,21 @@ -import { expect, test } from 'vitest' +import { describe, expect, test } from 'vitest' import type { ecmaVersion } from 'acorn' import { parse } from 'acorn' -import { detectModernBrowserDetector } from '../snippets' +import { + detectModernBrowserCode, + detectModernBrowserDetector, + dynamicFallbackInlineCode, + safari10NoModuleFix, + systemJSInlineCode, +} from '../snippets' const shouldFailVersions: ecmaVersion[] = [] for (let v = 2015; v <= 2019; v++) { shouldFailVersions.push(v as ecmaVersion) } -const shouldPassVersions: acorn.ecmaVersion[] = [] -for (let v = 2020; v <= 2022; v++) { +const shouldPassVersions: ecmaVersion[] = [] +for (let v = 2020; v <= 2024; v++) { shouldPassVersions.push(v as ecmaVersion) } @@ -34,3 +40,23 @@ for (const version of shouldPassVersions) { }).not.toThrow() }) } + +describe('snippets are valid', () => { + const codes = { + safari10NoModuleFix, + systemJSInlineCode, + detectModernBrowserCode, + dynamicFallbackInlineCode, + } + + for (const [name, value] of Object.entries(codes)) { + test(`${name} is valid JS`, () => { + expect(() => { + parse(value, { + ecmaVersion: 'latest', + sourceType: 'module', + }) + }).not.toThrow() + }) + } +})