(parser, expressionName, fn, property)
| 130 | * @returns {void} |
| 131 | */ |
| 132 | const setModuleConstant = (parser, expressionName, fn, property) => { |
| 133 | parser.hooks.expression |
| 134 | .for(expressionName) |
| 135 | .tap(PLUGIN_NAME, (expr) => { |
| 136 | const dep = new ConstDependency( |
| 137 | fn(parser.state.module), |
| 138 | /** @type {Range} */ |
| 139 | (expr.range) |
| 140 | ); |
| 141 | dep.loc = /** @type {DependencyLocation} */ (expr.loc); |
| 142 | parser.state.module.addPresentationalDependency(dep); |
| 143 | return true; |
| 144 | }); |
| 145 | |
| 146 | if ( |
| 147 | expressionName === IMPORT_META_FILENAME || |
| 148 | expressionName === IMPORT_META_DIRNAME |
| 149 | ) { |
| 150 | hooks.propertyInDestructuring.tap(PLUGIN_NAME, (usingProperty) => { |
| 151 | if (usingProperty.id === property) { |
| 152 | return `${property}: ${fn(parser.state.module)},`; |
| 153 | } |
| 154 | }); |
| 155 | } |
| 156 | }; |
| 157 | |
| 158 | /** |
| 159 | * Sets cached module constant. |
nothing calls this directly
no test coverage detected