-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(legacy)!: bump modern target to support async generator (#11896)
- Loading branch information
1 parent
d5b8f86
commit 55b9711
Showing
9 changed files
with
105 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expect, test } from 'vitest' | ||
import type { ecmaVersion } from 'acorn' | ||
import { parse } from 'acorn' | ||
import { detectModernBrowserDetector } 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++) { | ||
shouldPassVersions.push(v as ecmaVersion) | ||
} | ||
|
||
for (const version of shouldFailVersions) { | ||
test(`detect code should not be able to be parsed with ES${version}`, () => { | ||
expect(() => { | ||
parse(detectModernBrowserDetector, { | ||
ecmaVersion: version, | ||
sourceType: 'module', | ||
}) | ||
}).toThrow() | ||
}) | ||
} | ||
|
||
for (const version of shouldPassVersions) { | ||
test(`detect code should be able to be parsed with ES${version}`, () => { | ||
expect(() => { | ||
parse(detectModernBrowserDetector, { | ||
ecmaVersion: version, | ||
sourceType: 'module', | ||
}) | ||
}).not.toThrow() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// https://gist.github.com/samthor/64b114e4a4f539915a95b91ffd340acc | ||
// DO NOT ALTER THIS CONTENT | ||
export const safari10NoModuleFix = `!function(){var e=document,t=e.createElement("script");if(!("noModule"in t)&&"onbeforeload"in t){var n=!1;e.addEventListener("beforeload",(function(e){if(e.target===t)n=!0;else if(!e.target.hasAttribute("nomodule")||!n)return;e.preventDefault()}),!0),t.type="module",t.src=".",e.head.appendChild(t),t.remove()}}();` | ||
|
||
export const legacyPolyfillId = 'vite-legacy-polyfill' | ||
export const legacyEntryId = 'vite-legacy-entry' | ||
export const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))` | ||
|
||
const detectModernBrowserVarName = '__vite_is_modern_browser' | ||
export const detectModernBrowserDetector = | ||
'import.meta.url;import("_").catch(()=>1);async function* g(){};' | ||
export const detectModernBrowserCode = `${detectModernBrowserDetector}window.${detectModernBrowserVarName}=true;` | ||
export const dynamicFallbackInlineCode = `!function(){if(window.${detectModernBrowserVarName})return;console.warn("vite: loading legacy chunks, syntax error above and the same error below should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();` | ||
|
||
export const modernChunkLegacyGuard = `export function __vite_legacy_guard(){${detectModernBrowserDetector}};` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.