const regex = /(?<=^|[\n;](?:[\t ]*(?:\w+ )?)?)import\s*(?<type>type(?=\s+))?(?:[\s"']*(?<imports>[\w\t\n\r "$'*,/{}-]+?)\s+from\s*)?["']\s*(?<specifier>(?:(?<='\s*)[^']*[^\s'](?=\s*'))|(?:(?<="\s*)[^"]*[^\s"](?=\s*")))\s*["'](?:\s+assert\s+(?<assertion>{[\w\t\n\r "':]+?}))?(?=[\s;]*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<=^|[\\n;](?:[\\t ]*(?:\\w+ )?)?)import\\s*(?<type>type(?=\\s+))?(?:[\\s"\']*(?<imports>[\\w\\t\\n\\r "$\'*,\/{}-]+?)\\s+from\\s*)?["\']\\s*(?<specifier>(?:(?<=\'\\s*)[^\']*[^\\s\'](?=\\s*\'))|(?:(?<="\\s*)[^"]*[^\\s"](?=\\s*")))\\s*["\'](?:\\s+assert\\s+(?<assertion>{[\\w\\t\\n\\r "\':]+?}))?(?=[\\s;]*)', 'g')
const str = `/**
* @file Interfaces
* @module mlly/interfaces
*/
export type { default as DynamicImport } from './import-dynamic'
export type { default as StaticImport } from './import-static'
export type { default as ResolveOptions } from './options-resolve'
export type { default as ResolveAliasOptions } from './options-resolve-alias'
export type { default as Statement } from './statement'
export type { default as ExportStatement } from './statement-export'
export type { default as ImportStatement } from './statement-import'
export type { default as RequireStatement } from './statement-require'
import { CONDITIONS, RESOLVE_EXTENSIONS } from '#src/constants'
import type { ResolveOptions } from '#src/interfaces'
import type { SpecifierType } from '#src/types'
import isBuiltin from '@flex-development/is-builtin'
import { moduleResolve, type ErrnoException } from 'import-meta-resolve'
import { pathToFileURL, URL } from 'node:url'
import upath from 'upath'
import toBareSpecifier from './to-bare-specifier'
import toRelativeSpecifier from './to-relative-specifier'
import 'file:///home/dir/file.ts'
import pkg from './package.json' assert { type:'json' }
import * as color from 'colorette'
import consola from 'consola'
import { defu } from 'defu'
import type { Format } from 'esbuild'
import fse from 'fs-extra'
import * as pathe from 'pathe'
import { resolve } from 'node:path'
import url from 'node:url'
import type { PackageJson } from 'pkg-types'
import pb from 'pretty-bytes'
import { EXT_DTS_REGEX, IGNORE_PATTERNS } from './config/constants'
import loadBuildConfig from './config/load'
import type { Config, Entry, Result } from './interfaces'
import type { OutputExtension } from './types'
import { readPackage, type PackageJson } from "read-pkg"
import {OutputExtension} from './types'
import analyzeResults from './utils/analyze-results'
import esbuilder from './utils/esbuilder'; import write from './utils/write';import write2 from './utils/write'
// import write from './utils/write'
import 'side-effect.mjs'
import type StatementType from '../types/statement-type'
import type {
BuildOptions,
BuildResult,
OutputFile,
Plugin,
PluginBuild
} from './esbuild'
import defaultExport from "module-name";
import * as name from "module-name";
import { export1 } from "module-name";
import { export1 as alias1 } from "module-name";
import { default as alias } from "module-name";
import { export1, export2 } from "module-name";
import { export1, export2 as alias2 } from "module-name";
import { 'string name' as alias } from "module-name";
import { "string name" as alias } from "module-name";
import defaultExport, { export1 } from "module-name";
import defaultExport, * as name from "module-name";
import "module-name";
import 'module-name';
import './polyfill.mjs'
import { "h-i" as hi } from './hi.js'
import { 'j-k' as jk } from "./jk.js"
declare module '__fixtures__/values' {
import MAX_VALUE from '#fixtures/max-value'
import MIN_VALUE from '#fixtures/min-value'
}
const ERR_UNSUPPORTED_DIR_IMPORT: NodeErrorConstructor<
ErrorConstructor,
[string, string]
> = createNodeError(
ErrorCode.ERR_UNSUPPORTED_DIR_IMPORT,
Error,
'Directory import '%s' is not supported resolving ES modules imported from %s'
)
const text: string = await resolveModules(output.text, {
conditions: [format === 'esm' ? 'import' : 'require'],
ext: ext as Ext,
extensions,
parent
})
/**
* @example
* import write from './utils/write'
* write()
*/
import { 'j-k' as jk } from "./jk.js"`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions