(parser)
| 93 | * @returns {void} |
| 94 | */ |
| 95 | const handleConstValue = (parser) => { |
| 96 | // Only const is tracked; function/class names can be reassigned in sloppy mode. |
| 97 | // Re-exports always use getters: cross-module bindings may be mutable, |
| 98 | // and SideEffectsFlagPlugin can rewire connections skipping the template. |
| 99 | parser.hooks.preDeclarator.tap( |
| 100 | PLUGIN_NAME, |
| 101 | (declarator, statement) => { |
| 102 | // Detect top-level `const` declarations: |
| 103 | // - Tag ALL const bindings with CONST_BINDING_TAG (for const detection via tag system) |
| 104 | // - Carry inlined primitive value in tag data when eligible (for inline optimization) |
| 105 | if (statement.kind !== "const") return; |
| 106 | if (parser.scope.topLevelScope !== true) return; |
| 107 | |
| 108 | if (declarator.id.type === "Identifier") { |
| 109 | let inlinedValue; |
| 110 | if (this.options.inlineExports && declarator.init) { |
| 111 | const evaluated = parser.evaluateExpression(declarator.init); |
| 112 | inlinedValue = toInlinedValue(evaluated); |
| 113 | } |
| 114 | parser.tagVariable( |
| 115 | declarator.id.name, |
| 116 | CONST_BINDING_TAG, |
| 117 | inlinedValue ? { value: inlinedValue } : {}, |
| 118 | VariableInfoFlags.Normal |
| 119 | ); |
| 120 | } else { |
| 121 | // Handle destructuring patterns (ObjectPattern, ArrayPattern, etc.) |
| 122 | parser.enterPattern(declarator.id, (name) => { |
| 123 | parser.tagVariable( |
| 124 | name, |
| 125 | CONST_BINDING_TAG, |
| 126 | {}, |
| 127 | VariableInfoFlags.Normal |
| 128 | ); |
| 129 | }); |
| 130 | } |
| 131 | } |
| 132 | ); |
| 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * @param {JavascriptParser} parser the parser |
nothing calls this directly
no test coverage detected