MCPcopy Create free account
hub / github.com/babel/babel / stmtToDirective

Function stmtToDirective

packages/babel-parser/src/parser/statement.ts:140–163  ·  view source on GitHub ↗

* cast a Statement to a Directive. This method mutates input statement.

(stmt: N.ExpressionStatement)

Source from the content-addressed store, hash-verified

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)) {

Callers

nothing calls this directly

Calls 2

castNodeToMethod · 0.80
offsetToSourcePosMethod · 0.80

Tested by

no test coverage detected