#include <StringConstants.au3> ; to declare the Constants of StringRegExp
#include <Array.au3> ; UDF needed for _ArrayDisplay and _ArrayConcatenate
Local $sRegex = "(?u)(?<=^|[\n;](?:[\t ]*(?:\w+ )?)?)(?:(?:const\s*|let\s*|var\s*)?(?<imports>(?:[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*)|(?<=const\s*|let\s*|var\s*)(?:[\w\t\n\r "$'*,./:{}-]+?))\s*=\s*)?(?:await\s+)?(?<expression>import\((?<specifier>[\S\t\n\r]+?)(?:,\s*(?<options>\{\s*assert:.+[\w\t\n\r "':]+\}\s*\}))?\))"
Local $sString = "await import(foo)" & @CRLF & _
"await import('foo')" & @CRLF & _
"const foo = await import('bar')" & @CRLF & _
"const foo = await import(bar)" & @CRLF & _
"const promise = import('./foo');" & @CRLF & _
"const { readPackage } = await import('read-pkg')" & @CRLF & _
"const { " & @CRLF & _
" readPackageUp," & @CRLF & _
" readPackageUpSync" & @CRLF & _
"} = await import('read-pkg');" & @CRLF & _
"const {" & @CRLF & _
" addFive," & @CRLF & _
" addFour," & @CRLF & _
" addThree," & @CRLF & _
" addTwo," & @CRLF & _
" squareFive," & @CRLF & _
" squareFour," & @CRLF & _
" squareThree," & @CRLF & _
" squareTwo" & @CRLF & _
"} = await import('./lib')" & @CRLF & _
"await import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _
"var g;const{foo}=await import('bar');const{ foo }=await import('bar')" & @CRLF & _
"import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _
"import('buzz').then(() => console.log(res)).catch(() => ({}))" & @CRLF & _
"" & @CRLF & _
"import('buzz').catch(() => ({}))" & @CRLF & _
"" & @CRLF & _
"const foo = "./utils.mjs"; await import(foo)" & @CRLF & _
"" & @CRLF & _
"const { default: barData } =" & @CRLF & _
" await import('./bar.json');" & @CRLF & _
"" & @CRLF & _
"const { default: barData } =" & @CRLF & _
" await import('./bar.json', { assert: { type: 'json' } });" & @CRLF & _
"" & @CRLF & _
"(async () => {" & @CRLF & _
" if (somethingIsTrue) {" & @CRLF & _
" // import module for side effects" & @CRLF & _
" await import("/modules/my-module.js");" & @CRLF & _
" }" & @CRLF & _
"})();" & @CRLF & _
"" & @CRLF & _
"await import('__tests__/report.json', { " & @CRLF & _
" assert: { type: 'json' }" & @CRLF & _
"})" & @CRLF & _
"" & @CRLF & _
" await import('__tests__/report.json', {" & @CRLF & _
" assert: { type: 'json' }" & @CRLF & _
" })" & @CRLF & _
"" & @CRLF & _
"(async () => {" & @CRLF & _
" if (somethingIsTrue) {" & @CRLF & _
" const {" & @CRLF & _
" default: myDefault," & @CRLF & _
" foo," & @CRLF & _
" bar," & @CRLF & _
" } = await import("/modules/my-module.js");" & @CRLF & _
" }" & @CRLF & _
"})();" & @CRLF & _
"" & @CRLF & _
"const main = document.querySelector("main");" & @CRLF & _
"for (const link of document.querySelectorAll("nav > a")) {" & @CRLF & _
" link.addEventListener("click", (e) => {" & @CRLF & _
" e.preventDefault();" & @CRLF & _
"" & @CRLF & _
" import("/modules/my-module.js")" & @CRLF & _
" .then((module) => {" & @CRLF & _
" module.loadPageInto(main);" & @CRLF & _
" })" & @CRLF & _
" .then((module) => {" & @CRLF & _
" module.loadPageInto(main);" & @CRLF & _
" })" & @CRLF & _
" .then((module) => {" & @CRLF & _
" module.loadPageInto(main);" & @CRLF & _
" })" & @CRLF & _
" .catch((err) => {" & @CRLF & _
" main.textContent = err.message;" & @CRLF & _
" });" & @CRLF & _
" });" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"let myModule;" & @CRLF & _
"" & @CRLF & _
"if (typeof window === "undefined") {" & @CRLF & _
" myModule = await import("module-used-on-server");" & @CRLF & _
"} else {" & @CRLF & _
" myModule = await import("module-used-in-browser");" & @CRLF & _
"}" & @CRLF & _
"" & @CRLF & _
"Promise.all(" & @CRLF & _
" Array.from({ length: 10 }).map((_, index) =>" & @CRLF & _
" import(`/modules/module-${index}.js`)" & @CRLF & _
" )" & @CRLF & _
").then((modules) => modules.forEach((module) => module.load()));" & @CRLF & _
"" & @CRLF & _
" Array.from({ length: 10 }).map((_, index) => {" & @CRLF & _
" return import(`/modules/module-${index}.js`)" & @CRLF & _
" })" & @CRLF & _
"" & @CRLF & _
"'await import("foo")'" & @CRLF & _
""await import('foo')"" & @CRLF & _
"" & @CRLF & _
"// await import('foo')" & @CRLF & _
"" & @CRLF & _
"/**" & @CRLF & _
" * @example" & @CRLF & _
" * const { readPackageUp } = await import('read-pkg')" & @CRLF & _
" */" & @CRLF & _
""
Local $aArray = StringRegExp($sString, $sRegex, $STR_REGEXPARRAYGLOBALFULLMATCH)
Local $aFullArray[0]
For $i = 0 To UBound($aArray) -1
_ArrayConcatenate($aFullArray, $aArray[$i])
Next
$aArray = $aFullArray
; Present the entire match result
_ArrayDisplay($aArray, "Result")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm