(path, state)
| 138 | |
| 139 | Program: { |
| 140 | enter(path, state) { |
| 141 | const { file } = state; |
| 142 | let runtime: string = RUNTIME_DEFAULT; |
| 143 | |
| 144 | let source: string = IMPORT_SOURCE_DEFAULT; |
| 145 | let pragma: string = PRAGMA_DEFAULT; |
| 146 | let pragmaFrag: string = PRAGMA_FRAG_DEFAULT; |
| 147 | |
| 148 | let sourceSet = !!options.importSource; |
| 149 | let pragmaSet = !!options.pragma; |
| 150 | let pragmaFragSet = !!options.pragmaFrag; |
| 151 | |
| 152 | if (file.ast.comments) { |
| 153 | for (const comment of file.ast.comments) { |
| 154 | const sourceMatches = JSX_SOURCE_ANNOTATION_REGEX.exec( |
| 155 | comment.value, |
| 156 | ); |
| 157 | if (sourceMatches) { |
| 158 | source = sourceMatches[1]; |
| 159 | sourceSet = true; |
| 160 | } |
| 161 | |
| 162 | const runtimeMatches = JSX_RUNTIME_ANNOTATION_REGEX.exec( |
| 163 | comment.value, |
| 164 | ); |
| 165 | if (runtimeMatches) { |
| 166 | runtime = runtimeMatches[1]; |
| 167 | } |
| 168 | |
| 169 | const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value); |
| 170 | if (jsxMatches) { |
| 171 | pragma = jsxMatches[1]; |
| 172 | pragmaSet = true; |
| 173 | } |
| 174 | const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec( |
| 175 | comment.value, |
| 176 | ); |
| 177 | if (jsxFragMatches) { |
| 178 | pragmaFrag = jsxFragMatches[1]; |
| 179 | pragmaFragSet = true; |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | set(state, "runtime", runtime); |
| 185 | if (runtime === "classic") { |
| 186 | if (sourceSet) { |
| 187 | throw path.buildCodeFrameError( |
| 188 | `importSource cannot be set when runtime is classic.`, |
| 189 | ); |
| 190 | } |
| 191 | |
| 192 | const createElement = toMemberExpression(pragma); |
| 193 | const fragment = toMemberExpression(pragmaFrag); |
| 194 | |
| 195 | set(state, "id/createElement", () => t.cloneNode(createElement)); |
| 196 | set(state, "id/fragment", () => t.cloneNode(fragment)); |
| 197 |
nothing calls this directly
no test coverage detected