(parser, { importMeta })
| 139 | * @returns {void} |
| 140 | */ |
| 141 | const parserHandler = (parser, { importMeta }) => { |
| 142 | if (importMeta === false) { |
| 143 | const { importMetaName } = compilation.outputOptions; |
| 144 | if (importMetaName === "import.meta") return; |
| 145 | |
| 146 | parser.hooks.expression |
| 147 | .for(IMPORT_META) |
| 148 | .tap(PLUGIN_NAME, (metaProperty) => { |
| 149 | const dep = new ConstDependency( |
| 150 | /** @type {string} */ (importMetaName), |
| 151 | /** @type {Range} */ (metaProperty.range) |
| 152 | ); |
| 153 | dep.loc = /** @type {DependencyLocation} */ (metaProperty.loc); |
| 154 | parser.state.module.addPresentationalDependency(dep); |
| 155 | return true; |
| 156 | }); |
| 157 | return; |
| 158 | } |
| 159 | |
| 160 | // import.meta direct |
| 161 | const importMetaUrl = () => |
| 162 | JSON.stringify(getUrl(parser.state.module)); |
| 163 | const importMetaWebpackVersion = () => |
| 164 | JSON.stringify(WEBPACK_VERSION); |
| 165 | /** |
| 166 | * Import meta unknown property. |
| 167 | * @param {Members} members members |
| 168 | * @returns {string} error message |
| 169 | */ |
| 170 | const importMetaUnknownProperty = (members) => { |
| 171 | if (importMeta === "preserve-unknown") { |
| 172 | return `import.meta${propertyAccess(members, 0)}`; |
| 173 | } |
| 174 | return `${Template.toNormalComment( |
| 175 | `unsupported import.meta.${members.join(".")}` |
| 176 | )} undefined${propertyAccess(members, 1)}`; |
| 177 | }; |
| 178 | |
| 179 | parser.hooks.typeof |
| 180 | .for(IMPORT_META) |
| 181 | .tap( |
| 182 | PLUGIN_NAME, |
| 183 | toConstantDependency(parser, JSON.stringify("object")) |
| 184 | ); |
| 185 | parser.hooks.collectDestructuringAssignmentProperties.tap( |
| 186 | PLUGIN_NAME, |
| 187 | (expr) => { |
| 188 | if (expr.type === "MetaProperty") return true; |
| 189 | } |
| 190 | ); |
| 191 | parser.hooks.expression |
| 192 | .for(IMPORT_META) |
| 193 | .tap(PLUGIN_NAME, (metaProperty) => { |
| 194 | /** @type {RawRuntimeRequirements} */ |
| 195 | const runtimeRequirements = []; |
| 196 | const moduleArgument = parser.state.module.moduleArgument; |
| 197 | |
| 198 | const referencedPropertiesInDestructuring = |
nothing calls this directly
no test coverage detected