* cast a Statement to a Directive. This method mutates input statement.
(stmt: N.ExpressionStatement)
| 138 | * cast a Statement to a Directive. This method mutates input statement. |
| 139 | */ |
| 140 | stmtToDirective(stmt: N.ExpressionStatement): N.Directive { |
| 141 | const directive = this.castNodeTo(stmt, "Directive"); |
| 142 | |
| 143 | const directiveLiteral = this.castNodeTo( |
| 144 | stmt.expression, |
| 145 | "DirectiveLiteral", |
| 146 | ); |
| 147 | const expressionValue = directiveLiteral.value; |
| 148 | const raw = this.input.slice( |
| 149 | this.offsetToSourcePos(directiveLiteral.start!), |
| 150 | this.offsetToSourcePos(directiveLiteral.end!), |
| 151 | ); |
| 152 | const val = (directiveLiteral.value = raw.slice(1, -1)); // remove quotes |
| 153 | |
| 154 | this.addExtra(directiveLiteral, "raw", raw); |
| 155 | this.addExtra(directiveLiteral, "rawValue", val); |
| 156 | this.addExtra(directiveLiteral, "expressionValue", expressionValue); |
| 157 | |
| 158 | directive.value = directiveLiteral; |
| 159 | // @ts-expect-error delete non-optional properties |
| 160 | delete stmt.expression; |
| 161 | |
| 162 | return directive; |
| 163 | } |
| 164 | |
| 165 | parseInterpreterDirective(): N.InterpreterDirective | null { |
| 166 | if (!this.match(tt.interpreterDirective)) { |
nothing calls this directly
no test coverage detected