* cast a Statement to a Directive. This method mutates input statement.
(stmt: N.ExpressionStatement)
| 150 | * cast a Statement to a Directive. This method mutates input statement. |
| 151 | */ |
| 152 | stmtToDirective(stmt: N.ExpressionStatement): N.Directive { |
| 153 | const directive = this.castNodeTo(stmt, "Directive"); |
| 154 | |
| 155 | const directiveLiteral = this.castNodeTo( |
| 156 | stmt.expression, |
| 157 | "DirectiveLiteral", |
| 158 | ); |
| 159 | const expressionValue = directiveLiteral.value; |
| 160 | const raw = this.input.slice( |
| 161 | this.offsetToSourcePos(directiveLiteral.start!), |
| 162 | this.offsetToSourcePos(directiveLiteral.end!), |
| 163 | ); |
| 164 | const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes |
| 165 | |
| 166 | this.addExtra(directiveLiteral, "raw", raw); |
| 167 | this.addExtra(directiveLiteral, "rawValue", val); |
| 168 | this.addExtra(directiveLiteral, "expressionValue", expressionValue); |
| 169 | |
| 170 | directive.value = directiveLiteral; |
| 171 | // @ts-expect-error delete non-optional properties |
| 172 | delete stmt.expression; |
| 173 | |
| 174 | return directive; |
| 175 | } |
| 176 | |
| 177 | parseInterpreterDirective(): N.InterpreterDirective | null { |
| 178 | if (!this.match(tt.interpreterDirective)) { |
nothing calls this directly
no test coverage detected