"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
exports . default = void 0 ;
function _sourceMap ( ) {
const data = _interopRequireDefault ( require ( "@parcel/source-map" ) ) ;
_sourceMap = function ( ) {
return data ;
} ;
return data ;
}
function _plugin ( ) {
const data = require ( "@parcel/plugin" ) ;
_plugin = function ( ) {
return data ;
} ;
return data ;
}
var _native = require ( "../native" ) ;
function _path ( ) {
const data = _interopRequireDefault ( require ( "path" ) ) ;
_path = function ( ) {
return data ;
} ;
return data ;
}
function _browserslist ( ) {
const data = _interopRequireDefault ( require ( "browserslist" ) ) ;
_browserslist = function ( ) {
return data ;
} ;
return data ;
}
function _semver ( ) {
const data = _interopRequireDefault ( require ( "semver" ) ) ;
_semver = function ( ) {
return data ;
} ;
return data ;
}
function _nullthrows ( ) {
const data = _interopRequireDefault ( require ( "nullthrows" ) ) ;
_nullthrows = function ( ) {
return data ;
} ;
return data ;
}
function _diagnostic ( ) {
const data = _interopRequireWildcard ( require ( "@parcel/diagnostic" ) ) ;
_diagnostic = function ( ) {
return data ;
} ;
return data ;
}
function _utils ( ) {
const data = require ( "@parcel/utils" ) ;
_utils = function ( ) {
return data ;
} ;
return data ;
}
function _micromatch ( ) {
const data = require ( "micromatch" ) ;
_micromatch = function ( ) {
return data ;
} ;
return data ;
}
function _getRequireWildcardCache ( ) { if ( typeof WeakMap !== "function" ) return null ; var cache = new WeakMap ( ) ; _getRequireWildcardCache = function ( ) { return cache ; } ; return cache ; }
function _interopRequireWildcard ( obj ) { if ( obj && obj . _ _esModule ) { return obj ; } if ( obj === null || typeof obj !== "object" && typeof obj !== "function" ) { return { default : obj } ; } var cache = _getRequireWildcardCache ( ) ; if ( cache && cache . has ( obj ) ) { return cache . get ( obj ) ; } var newObj = { } ; var hasPropertyDescriptor = Object . defineProperty && Object . getOwnPropertyDescriptor ; for ( var key in obj ) { if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) { var desc = hasPropertyDescriptor ? Object . getOwnPropertyDescriptor ( obj , key ) : null ; if ( desc && ( desc . get || desc . set ) ) { Object . defineProperty ( newObj , key , desc ) ; } else { newObj [ key ] = obj [ key ] ; } } } newObj . default = obj ; if ( cache ) { cache . set ( obj , newObj ) ; } return newObj ; }
function _interopRequireDefault ( obj ) { return obj && obj . _ _esModule ? obj : { default : obj } ; }
const JSX _EXTENSIONS = {
jsx : true ,
tsx : true
} ;
const JSX _PRAGMA = {
react : {
pragma : 'React.createElement' ,
pragmaFrag : 'React.Fragment' ,
automatic : '>= 17.0.0'
} ,
preact : {
pragma : 'h' ,
pragmaFrag : 'Fragment' ,
automatic : '>= 10.5.0'
} ,
nervjs : {
pragma : 'Nerv.createElement' ,
pragmaFrag : undefined ,
automatic : undefined
} ,
hyperapp : {
pragma : 'h' ,
pragmaFrag : undefined ,
automatic : undefined
}
} ;
const BROWSER _MAPPING = {
and _chr : 'chrome' ,
and _ff : 'firefox' ,
ie _mob : 'ie' ,
ios _saf : 'ios' ,
op _mob : 'opera' ,
and _qq : null ,
and _uc : null ,
baidu : null ,
bb : null ,
kaios : null ,
op _mini : null
} ; // List of browsers to exclude when the esmodule target is specified.
// Based on https://caniuse.com/#feat=es6-module
const ESMODULE _BROWSERS = [ 'not ie <= 11' , 'not edge < 16' , 'not firefox < 60' , 'not chrome < 61' , 'not safari < 11' , 'not opera < 48' , 'not ios_saf < 11' , 'not op_mini all' , 'not android < 76' , 'not blackberry > 0' , 'not op_mob > 0' , 'not and_chr < 76' , 'not and_ff < 68' , 'not ie_mob > 0' , 'not and_uc > 0' , 'not samsung < 8.2' , 'not and_qq > 0' , 'not baidu > 0' , 'not kaios > 0' ] ;
const CONFIG _SCHEMA = {
type : 'object' ,
properties : {
inlineFS : {
type : 'boolean'
} ,
inlineEnvironment : {
oneOf : [ {
type : 'boolean'
} , {
type : 'array' ,
items : {
type : 'string'
}
} ]
}
} ,
additionalProperties : false
} ;
const SCRIPT _ERRORS = {
browser : {
message : 'Browser scripts cannot have imports or exports.' ,
hint : 'Add the type="module" attribute to the <script> tag.'
} ,
'web-worker' : {
message : 'Web workers cannot have imports or exports without the `type: "module"` option.' ,
hint : "Add {type: 'module'} as a second argument to the Worker constructor."
} ,
'service-worker' : {
message : 'Service workers cannot have imports or exports without the `type: "module"` option.' ,
hint : "Add {type: 'module'} as a second argument to the navigator.serviceWorker.register() call."
}
} ;
var _default = new ( _plugin ( ) . Transformer ) ( {
async loadConfig ( {
config ,
options
} ) {
let pkg = await config . getPackage ( ) ;
let isJSX , pragma , pragmaFrag , jsxImportSource , automaticJSXRuntime , reactRefresh , decorators ;
if ( config . isSource ) {
var _pkg$dependencies2 , _pkg$devDependencies2 , _pkg$peerDependencies2 , _tsconfig$contents ;
let reactLib ;
if ( pkg !== null && pkg !== void 0 && pkg . alias && pkg . alias [ 'react' ] ) {
// e.g.: `{ alias: { "react": "preact/compat" } }`
reactLib = 'react' ;
} else {
// Find a dependency that we can map to a JSX pragma
reactLib = Object . keys ( JSX _PRAGMA ) . find ( libName => {
var _pkg$dependencies , _pkg$devDependencies , _pkg$peerDependencies ;
return ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$dependencies = pkg . dependencies ) === null || _pkg$dependencies === void 0 ? void 0 : _pkg$dependencies [ libName ] ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$devDependencies = pkg . devDependencies ) === null || _pkg$devDependencies === void 0 ? void 0 : _pkg$devDependencies [ libName ] ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$peerDependencies = pkg . peerDependencies ) === null || _pkg$peerDependencies === void 0 ? void 0 : _pkg$peerDependencies [ libName ] ) ;
} ) ;
}
reactRefresh = options . hmrOptions && options . mode === 'development' && Boolean ( ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$dependencies2 = pkg . dependencies ) === null || _pkg$dependencies2 === void 0 ? void 0 : _pkg$dependencies2 . react ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$devDependencies2 = pkg . devDependencies ) === null || _pkg$devDependencies2 === void 0 ? void 0 : _pkg$devDependencies2 . react ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$peerDependencies2 = pkg . peerDependencies ) === null || _pkg$peerDependencies2 === void 0 ? void 0 : _pkg$peerDependencies2 . react ) ) ;
let tsconfig = await config . getConfigFrom ( options . projectRoot + '/index' , [ 'tsconfig.json' , 'jsconfig.json' ] ) ;
let compilerOptions = tsconfig === null || tsconfig === void 0 ? void 0 : ( _tsconfig$contents = tsconfig . contents ) === null || _tsconfig$contents === void 0 ? void 0 : _tsconfig$contents . compilerOptions ; // Use explicitly defined JSX options in tsconfig.json over inferred values from dependencies.
pragma = ( compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsxFactory ) || ( reactLib ? JSX _PRAGMA [ reactLib ] . pragma : undefined ) ;
pragmaFrag = ( compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsxFragmentFactory ) || ( reactLib ? JSX _PRAGMA [ reactLib ] . pragmaFrag : undefined ) ;
if ( ( compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsx ) === 'react-jsx' || ( compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsx ) === 'react-jsxdev' || compilerOptions !== null && compilerOptions !== void 0 && compilerOptions . jsxImportSource ) {
jsxImportSource = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsxImportSource ;
automaticJSXRuntime = true ;
} else if ( reactLib ) {
var _JSX _PRAGMA$reactLib , _pkg$dependencies3 , _pkg$devDependencies3 , _pkg$peerDependencies3 , _semver$minVersion ;
let automaticVersion = ( _JSX _PRAGMA$reactLib = JSX _PRAGMA [ reactLib ] ) === null || _JSX _PRAGMA$reactLib === void 0 ? void 0 : _JSX _PRAGMA$reactLib . automatic ;
let reactLibVersion = ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$dependencies3 = pkg . dependencies ) === null || _pkg$dependencies3 === void 0 ? void 0 : _pkg$dependencies3 [ reactLib ] ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$devDependencies3 = pkg . devDependencies ) === null || _pkg$devDependencies3 === void 0 ? void 0 : _pkg$devDependencies3 [ reactLib ] ) || ( pkg === null || pkg === void 0 ? void 0 : ( _pkg$peerDependencies3 = pkg . peerDependencies ) === null || _pkg$peerDependencies3 === void 0 ? void 0 : _pkg$peerDependencies3 [ reactLib ] ) ;
let minReactLibVersion = reactLibVersion != null && reactLibVersion !== '*' ? ( _semver$minVersion = _semver ( ) . default . minVersion ( reactLibVersion ) ) === null || _semver$minVersion === void 0 ? void 0 : _semver$minVersion . toString ( ) : null ;
automaticJSXRuntime = automaticVersion && ! ( compilerOptions !== null && compilerOptions !== void 0 && compilerOptions . jsxFactory ) && minReactLibVersion != null && _semver ( ) . default . satisfies ( minReactLibVersion , automaticVersion ) ;
if ( automaticJSXRuntime ) {
jsxImportSource = reactLib ;
}
}
isJSX = Boolean ( ( compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . jsx ) || pragma ) ;
decorators = compilerOptions === null || compilerOptions === void 0 ? void 0 : compilerOptions . experimentalDecorators ;
} // Check if we should ignore fs calls
// See https://github.com/defunctzombie/node-browser-resolve#skip
let ignoreFS = pkg && pkg . browser && typeof pkg . browser === 'object' && pkg . browser . fs === false ;
let result = await config . getConfigFrom ( _path ( ) . default . join ( options . projectRoot , 'index' ) , [ 'package.json' ] ) ;
let rootPkg = result === null || result === void 0 ? void 0 : result . contents ;
let inlineEnvironment = config . isSource ;
let inlineFS = ! ignoreFS ;
if ( result && rootPkg !== null && rootPkg !== void 0 && rootPkg [ '@parcel/transformer-js' ] ) {
var _rootPkg$ParcelTran , _rootPkg$ParcelTran2 , _rootPkg$ParcelTran3 , _rootPkg$ParcelTran4 ;
_utils ( ) . validateSchema . diagnostic ( CONFIG _SCHEMA , {
data : rootPkg [ '@parcel/transformer-js' ] ,
// FIXME
source : await options . inputFS . readFile ( result . filePath , 'utf8' ) ,
filePath : result . filePath ,
prependKey : ` / ${ ( 0 , _diagnostic ( ) . encodeJSONKeyComponent ) ( '@parcel/transformer-js' ) } `
} , // FIXME
'@parcel/transformer-js' , 'Invalid config for @parcel/transformer-js' ) ;
inlineEnvironment = ( _rootPkg$ParcelTran = ( _rootPkg$ParcelTran2 = rootPkg [ '@parcel/transformer-js' ] ) === null || _rootPkg$ParcelTran2 === void 0 ? void 0 : _rootPkg$ParcelTran2 . inlineEnvironment ) !== null && _rootPkg$ParcelTran !== void 0 ? _rootPkg$ParcelTran : inlineEnvironment ;
inlineFS = ( _rootPkg$ParcelTran3 = ( _rootPkg$ParcelTran4 = rootPkg [ '@parcel/transformer-js' ] ) === null || _rootPkg$ParcelTran4 === void 0 ? void 0 : _rootPkg$ParcelTran4 . inlineFS ) !== null && _rootPkg$ParcelTran3 !== void 0 ? _rootPkg$ParcelTran3 : inlineFS ;
}
return {
isJSX ,
automaticJSXRuntime ,
jsxImportSource ,
pragma ,
pragmaFrag ,
inlineEnvironment ,
inlineFS ,
reactRefresh ,
decorators
} ;
} ,
async transform ( {
asset ,
config ,
options ,
logger
} ) {
let [ code , originalMap ] = await Promise . all ( [ asset . getBuffer ( ) , asset . getMap ( ) , _native . init ] ) ;
let targets ;
if ( asset . isSource ) {
if ( asset . env . isElectron ( ) && asset . env . engines . electron ) {
var _semver$minVersion2 ;
targets = {
electron : ( _semver$minVersion2 = _semver ( ) . default . minVersion ( asset . env . engines . electron ) ) === null || _semver$minVersion2 === void 0 ? void 0 : _semver$minVersion2 . toString ( )
} ;
} else if ( asset . env . isBrowser ( ) && asset . env . engines . browsers ) {
targets = { } ;
let browsers = Array . isArray ( asset . env . engines . browsers ) ? asset . env . engines . browsers : [ asset . env . engines . browsers ] ; // If the output format is esmodule, exclude browsers
// that support them natively so that we transpile less.
if ( asset . env . outputFormat === 'esmodule' ) {
browsers = [ ... browsers , ... ESMODULE _BROWSERS ] ;
}
browsers = ( 0 , _browserslist ( ) . default ) ( browsers ) ;
for ( let browser of browsers ) {
let [ name , version ] = browser . split ( ' ' ) ;
if ( BROWSER _MAPPING . hasOwnProperty ( name ) ) {
name = BROWSER _MAPPING [ name ] ;
if ( ! name ) {
continue ;
}
}
let [ major , minor = '0' , patch = '0' ] = version . split ( '-' ) [ 0 ] . split ( '.' ) ;
let semverVersion = ` ${ major } . ${ minor } . ${ patch } ` ;
if ( targets [ name ] == null || _semver ( ) . default . gt ( targets [ name ] , semverVersion ) ) {
targets [ name ] = semverVersion ;
}
}
} else if ( asset . env . isNode ( ) && asset . env . engines . node ) {
var _semver$minVersion3 ;
targets = {
node : ( _semver$minVersion3 = _semver ( ) . default . minVersion ( asset . env . engines . node ) ) === null || _semver$minVersion3 === void 0 ? void 0 : _semver$minVersion3 . toString ( )
} ;
}
}
let env = { } ;
if ( ! ( config !== null && config !== void 0 && config . inlineEnvironment ) ) {
if ( options . env . NODE _ENV != null ) {
env . NODE _ENV = options . env . NODE _ENV ;
}
} else if ( Array . isArray ( config === null || config === void 0 ? void 0 : config . inlineEnvironment ) ) {
for ( let key in options . env ) {
if ( ( 0 , _micromatch ( ) . isMatch ) ( key , config . inlineEnvironment ) ) {
env [ key ] = String ( options . env [ key ] ) ;
}
}
} else {
for ( let key in options . env ) {
if ( ! key . startsWith ( 'npm_' ) ) {
env [ key ] = String ( options . env [ key ] ) ;
}
}
}
let supportsModuleWorkers = asset . env . shouldScopeHoist && asset . env . supports ( 'worker-module' , true ) ;
let isJSX = Boolean ( config === null || config === void 0 ? void 0 : config . isJSX ) ;
if ( asset . isSource ) {
if ( asset . type === 'ts' ) {
isJSX = false ;
} else if ( ! isJSX ) {
isJSX = Boolean ( JSX _EXTENSIONS [ asset . type ] ) ;
}
}
let {
dependencies ,
code : compiledCode ,
map ,
shebang ,
hoist _result ,
needs _esm _helpers ,
diagnostics ,
used _env
} = ( 0 , _native . transform ) ( {
filename : asset . filePath ,
code ,
module _id : asset . id ,
project _root : options . projectRoot ,
replace _env : ! asset . env . isNode ( ) ,
inline _fs : Boolean ( config === null || config === void 0 ? void 0 : config . inlineFS ) && ! asset . env . isNode ( ) ,
insert _node _globals : ! asset . env . isNode ( ) ,
is _browser : asset . env . isBrowser ( ) ,
is _worker : asset . env . isWorker ( ) ,
env ,
is _type _script : asset . type === 'ts' || asset . type === 'tsx' ,
is _jsx : isJSX ,
jsx _pragma : config === null || config === void 0 ? void 0 : config . pragma ,
jsx _pragma _frag : config === null || config === void 0 ? void 0 : config . pragmaFrag ,
automatic _jsx _runtime : Boolean ( config === null || config === void 0 ? void 0 : config . automaticJSXRuntime ) ,
jsx _import _source : config === null || config === void 0 ? void 0 : config . jsxImportSource ,
is _development : options . mode === 'development' ,
react _refresh : asset . env . isBrowser ( ) && ! asset . env . isWorker ( ) && ! asset . env . isWorklet ( ) && Boolean ( config === null || config === void 0 ? void 0 : config . reactRefresh ) ,
decorators : Boolean ( config === null || config === void 0 ? void 0 : config . decorators ) ,
targets ,
source _maps : ! ! asset . env . sourceMap ,
scope _hoist : asset . env . shouldScopeHoist && asset . env . sourceType !== 'script' ,
source _type : asset . env . sourceType === 'script' ? 'Script' : 'Module' ,
supports _module _workers : supportsModuleWorkers ,
is _library : asset . env . isLibrary ,
is _esm _output : asset . env . outputFormat === 'esmodule' ,
trace _bailouts : options . logLevel === 'verbose'
} ) ;
let convertLoc = loc => {
var _asset$meta$startLine , _asset$meta$startLine2 ;
let location = {
filePath : asset . filePath ,
start : {
line : loc . start _line + Number ( ( _asset$meta$startLine = asset . meta . startLine ) !== null && _asset$meta$startLine !== void 0 ? _asset$meta$startLine : 1 ) - 1 ,
column : loc . start _col
} ,
end : {
line : loc . end _line + Number ( ( _asset$meta$startLine2 = asset . meta . startLine ) !== null && _asset$meta$startLine2 !== void 0 ? _asset$meta$startLine2 : 1 ) - 1 ,
column : loc . end _col
}
} ; // If there is an original source map, use it to remap to the original source location.
if ( originalMap ) {
location = ( 0 , _utils ( ) . remapSourceLocation ) ( location , originalMap ) ;
}
return location ;
} ;
if ( diagnostics ) {
let errors = diagnostics . filter ( d => d . severity === 'Error' || d . severity === 'SourceError' && asset . isSource ) ;
let warnings = diagnostics . filter ( d => d . severity === 'Warning' || d . severity === 'SourceError' && ! asset . isSource ) ;
let convertDiagnostic = diagnostic => {
var _diagnostic$code _high ;
let message = diagnostic . message ;
if ( message === 'SCRIPT_ERROR' ) {
let err = SCRIPT _ERRORS [ asset . env . context ] ;
message = ( err === null || err === void 0 ? void 0 : err . message ) || SCRIPT _ERRORS . browser . message ;
}
let res = {
message ,
codeFrames : [ {
filePath : asset . filePath ,
codeHighlights : ( _diagnostic$code _high = diagnostic . code _highlights ) === null || _diagnostic$code _high === void 0 ? void 0 : _diagnostic$code _high . map ( highlight => {
let {
start ,
end
} = convertLoc ( highlight . loc ) ;
return {
message : highlight . message ,
start ,
end
} ;
} )
} ] ,
hints : diagnostic . hints
} ;
if ( diagnostic . documentation _url ) {
res . documentationURL = diagnostic . documentation _url ;
}
if ( diagnostic . show _environment ) {
if ( asset . env . loc && asset . env . loc . filePath !== asset . filePath ) {
var _res$codeFrames ;
( _res$codeFrames = res . codeFrames ) === null || _res$codeFrames === void 0 ? void 0 : _res$codeFrames . push ( {
filePath : asset . env . loc . filePath ,
codeHighlights : [ {
start : asset . env . loc . start ,
end : asset . env . loc . end ,
message : 'The environment was originally created here'
} ]
} ) ;
}
let err = SCRIPT _ERRORS [ asset . env . context ] ;
if ( err ) {
if ( ! res . hints ) {
res . hints = [ err . hint ] ;
} else {
res . hints . push ( err . hint ) ;
}
}
}
return res ;
} ;
if ( errors . length > 0 ) {
throw new ( _diagnostic ( ) . default ) ( {
diagnostic : errors . map ( convertDiagnostic )
} ) ;
}
logger . warn ( warnings . map ( convertDiagnostic ) ) ;
}
if ( shebang ) {
asset . meta . interpreter = shebang ;
}
for ( let env of used _env ) {
asset . invalidateOnEnvChange ( env ) ;
}
for ( let dep of dependencies ) {
if ( dep . kind === 'WebWorker' ) {
// Use native ES module output if the worker was created with `type: 'module'` and all targets
// support native module workers. Only do this if parent asset output format is also esmodule so that
// assets can be shared between workers and the main thread in the global output format.
let outputFormat ;
if ( asset . env . outputFormat === 'esmodule' && dep . source _type === 'Module' && supportsModuleWorkers ) {
outputFormat = 'esmodule' ;
} else {
outputFormat = asset . env . outputFormat === 'commonjs' ? 'commonjs' : 'global' ;
}
let loc = convertLoc ( dep . loc ) ;
asset . addURLDependency ( dep . specifier , {
loc ,
env : {
context : 'web-worker' ,
sourceType : dep . source _type === 'Module' ? 'module' : 'script' ,
outputFormat ,
loc
} ,
meta : {
webworker : true ,
placeholder : dep . placeholder
}
} ) ;
} else if ( dep . kind === 'ServiceWorker' ) {
let loc = convertLoc ( dep . loc ) ;
asset . addURLDependency ( dep . specifier , {
loc ,
needsStableName : true ,
env : {
context : 'service-worker' ,
sourceType : dep . source _type === 'Module' ? 'module' : 'script' ,
outputFormat : 'global' ,
// TODO: module service worker support
loc
} ,
meta : {
placeholder : dep . placeholder
}
} ) ;
} else if ( dep . kind === 'Worklet' ) {
let loc = convertLoc ( dep . loc ) ;
asset . addURLDependency ( dep . specifier , {
loc ,
env : {
context : 'worklet' ,
sourceType : 'module' ,
outputFormat : 'esmodule' ,
// Worklets require ESM
loc
} ,
meta : {
placeholder : dep . placeholder
}
} ) ;
} else if ( dep . kind === 'Url' ) {
asset . addURLDependency ( dep . specifier , {
bundleBehavior : 'isolated' ,
loc : convertLoc ( dep . loc ) ,
meta : {
placeholder : dep . placeholder
}
} ) ;
} else if ( dep . kind === 'File' ) {
asset . invalidateOnFileChange ( dep . specifier ) ;
} else {
let meta = {
kind : dep . kind
} ;
if ( dep . attributes ) {
meta . importAttributes = dep . attributes ;
}
if ( dep . placeholder ) {
meta . placeholder = dep . placeholder ;
}
let env ;
if ( dep . kind === 'DynamicImport' ) {
// https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability)
if ( asset . env . isWorklet ( ) || asset . env . context === 'service-worker' ) {
let loc = convertLoc ( dep . loc ) ;
let diagnostic = {
message : ` import() is not allowed in ${ asset . env . isWorklet ( ) ? 'worklets' : 'service workers' } . ` ,
codeFrames : [ {
filePath : asset . filePath ,
codeHighlights : [ {
start : loc . start ,
end : loc . end
} ]
} ] ,
hints : [ 'Try using a static `import`.' ]
} ;
if ( asset . env . loc ) {
diagnostic . codeFrames . push ( {
filePath : asset . env . loc . filePath ,
codeHighlights : [ {
start : asset . env . loc . start ,
end : asset . env . loc . end ,
message : 'The environment was originally created here'
} ]
} ) ;
}
throw new ( _diagnostic ( ) . default ) ( {
diagnostic
} ) ;
} // If all of the target engines support dynamic import natively,
// we can output native ESM if scope hoisting is enabled.
// Only do this for scripts, rather than modules in the global
// output format so that assets can be shared between the bundles.
let outputFormat = asset . env . outputFormat ;
if ( asset . env . sourceType === 'script' && asset . env . shouldScopeHoist && asset . env . supports ( 'dynamic-import' , true ) ) {
outputFormat = 'esmodule' ;
}
env = {
sourceType : 'module' ,
outputFormat ,
loc : convertLoc ( dep . loc )
} ;
} // Always bundle helpers, even with includeNodeModules: false, except if this is a library.
let isHelper = dep . is _helper && ! dep . specifier . endsWith ( '/jsx-runtime' ) ;
if ( isHelper && ! asset . env . isLibrary ) {
env = { ... env ,
includeNodeModules : true
} ;
}
asset . addDependency ( {
specifier : dep . specifier ,
specifierType : dep . kind === 'Require' ? 'commonjs' : 'esm' ,
loc : convertLoc ( dep . loc ) ,
priority : dep . kind === 'DynamicImport' ? 'lazy' : 'sync' ,
isOptional : dep . is _optional ,
meta ,
resolveFrom : isHelper ? _ _filename : undefined ,
env
} ) ;
}
}
asset . meta . id = asset . id ;
if ( hoist _result ) {
asset . symbols . ensure ( ) ;
for ( let {
exported ,
local ,
loc
} of hoist _result . exported _symbols ) {
asset . symbols . set ( exported , local , convertLoc ( loc ) ) ;
}
let deps = new Map ( asset . getDependencies ( ) . map ( dep => {
var _dep$meta$placeholder ;
return [ ( _dep$meta$placeholder = dep . meta . placeholder ) !== null && _dep$meta$placeholder !== void 0 ? _dep$meta$placeholder : dep . specifier , dep ] ;
} ) ) ;
for ( let dep of deps . values ( ) ) {
dep . symbols . ensure ( ) ;
}
for ( let {
source ,
local ,
imported ,
loc
} of hoist _result . imported _symbols ) {
let dep = deps . get ( source ) ;
if ( ! dep ) continue ;
dep . symbols . set ( imported , local , convertLoc ( loc ) ) ;
}
for ( let {
source ,
local ,
imported ,
loc
} of hoist _result . re _exports ) {
let dep = deps . get ( source ) ;
if ( ! dep ) continue ;
if ( local === '*' && imported === '*' ) {
dep . symbols . set ( '*' , '*' , convertLoc ( loc ) , true ) ;
} else {
var _dep$symbols$get$loca , _dep$symbols$get ;
let reExportName = ( _dep$symbols$get$loca = ( _dep$symbols$get = dep . symbols . get ( imported ) ) === null || _dep$symbols$get === void 0 ? void 0 : _dep$symbols$get . local ) !== null && _dep$symbols$get$loca !== void 0 ? _dep$symbols$get$loca : ` $ ${ asset . id } $ re_export $ ${ local } ` ;
asset . symbols . set ( local , reExportName ) ;
dep . symbols . set ( imported , reExportName , convertLoc ( loc ) , true ) ;
}
}
for ( let specifier of hoist _result . wrapped _requires ) {
let dep = deps . get ( specifier ) ;
if ( ! dep ) continue ;
dep . meta . shouldWrap = true ;
}
for ( let name in hoist _result . dynamic _imports ) {
let dep = deps . get ( hoist _result . dynamic _imports [ name ] ) ;
if ( ! dep ) continue ;
dep . meta . promiseSymbol = name ;
}
if ( hoist _result . self _references . length > 0 ) {
let symbols = new Map ( ) ;
for ( let name of hoist _result . self _references ) {
// Do not create a self-reference for the `default` symbol unless we have seen an __esModule flag.
if ( name === 'default' && ! asset . symbols . hasExportSymbol ( '__esModule' ) ) {
continue ;
}
let local = ( 0 , _nullthrows ( ) . default ) ( asset . symbols . get ( name ) ) . local ;
symbols . set ( name , {
local ,
isWeak : false ,
loc : null
} ) ;
}
asset . addDependency ( {
specifier : ` ./ ${ _path ( ) . default . basename ( asset . filePath ) } ` ,
specifierType : 'esm' ,
symbols
} ) ;
} // Add * symbol if there are CJS exports, no imports/exports at all, or the asset is wrapped.
// This allows accessing symbols that don't exist without errors in symbol propagation.
if ( hoist _result . has _cjs _exports || ! hoist _result . is _esm && deps . size === 0 && Object . keys ( hoist _result . exported _symbols ) . length === 0 || hoist _result . should _wrap && ! asset . symbols . hasExportSymbol ( '*' ) ) {
asset . symbols . set ( '*' , ` $ ${ asset . id } $ exports ` ) ;
}
asset . meta . hasCJSExports = hoist _result . has _cjs _exports ;
asset . meta . staticExports = hoist _result . static _cjs _exports ;
asset . meta . shouldWrap = hoist _result . should _wrap ;
} else if ( needs _esm _helpers ) {
asset . addDependency ( {
specifier : '@parcel/transformer-js/src/esmodule-helpers.js' ,
specifierType : 'esm' ,
resolveFrom : _ _filename ,
env : {
includeNodeModules : {
'@parcel/transformer-js' : true
}
}
} ) ;
}
asset . type = 'js' ;
asset . setBuffer ( compiledCode ) ;
if ( map ) {
let sourceMap = new ( _sourceMap ( ) . default ) ( options . projectRoot ) ;
sourceMap . addVLQMap ( JSON . parse ( map ) ) ;
if ( originalMap ) {
sourceMap . extends ( originalMap ) ;
}
asset . setMap ( sourceMap ) ;
}
return [ asset ] ;
}
} ) ;
exports . default = _default ;