@@ -174,30 +174,31 @@ public class ASTExtractor {
174
174
private final RegExpExtractor regexpExtractor ;
175
175
private final ExtractorConfig config ;
176
176
177
- public ASTExtractor (ExtractorConfig config , LexicalExtractor lexicalExtractor , ScopeManager scopeManager ) {
177
+ public ASTExtractor (
178
+ ExtractorConfig config , LexicalExtractor lexicalExtractor , ScopeManager scopeManager ) {
178
179
this .config = config ;
179
180
this .trapwriter = lexicalExtractor .getTrapwriter ();
180
181
this .locationManager = lexicalExtractor .getLocationManager ();
181
182
this .contextManager = new SyntacticContextManager ();
182
183
this .scopeManager = scopeManager ;
183
184
this .lexicalExtractor = lexicalExtractor ;
184
185
this .regexpExtractor = new RegExpExtractor (trapwriter , locationManager );
185
- this .toplevelLabel = makeTopLevelLabel (trapwriter , locationManager .getFileLabel (), locationManager .getStartLine (), locationManager .getStartColumn ());
186
+ this .toplevelLabel =
187
+ makeTopLevelLabel (
188
+ trapwriter ,
189
+ locationManager .getFileLabel (),
190
+ locationManager .getStartLine (),
191
+ locationManager .getStartColumn ());
186
192
}
187
193
188
194
/**
189
195
* Returns the label for the top-level starting at the given location.
190
- * <p>
191
- * May be used to refer to the top-level before it has been extracted.
196
+ *
197
+ * <p> May be used to refer to the top-level before it has been extracted.
192
198
*/
193
- public static Label makeTopLevelLabel (TrapWriter trapWriter , Label fileLabel , int startLine , int startColumn ) {
194
- return trapWriter .globalID (
195
- "script;{"
196
- + fileLabel
197
- + "},"
198
- + startLine
199
- + ','
200
- + startColumn );
199
+ public static Label makeTopLevelLabel (
200
+ TrapWriter trapWriter , Label fileLabel , int startLine , int startColumn ) {
201
+ return trapWriter .globalID ("script;{" + fileLabel + "}," + startLine + ',' + startColumn );
201
202
}
202
203
203
204
public TrapWriter getTrapwriter () {
@@ -254,8 +255,8 @@ public enum IdContext {
254
255
TYPE_LABEL ,
255
256
256
257
/**
257
- * An identifier that refers to a variable from inside a type, i.e. the operand to a
258
- * <code> typeof</code> type or left operand to an <code>is</code> type.
258
+ * An identifier that refers to a variable from inside a type, i.e. the operand to a <code>
259
+ * typeof</code> type or left operand to an <code>is</code> type.
259
260
*
260
261
* <p>This is generally treated as a type, except a variable binding will be emitted for it.
261
262
*/
@@ -273,16 +274,16 @@ public enum IdContext {
273
274
/**
274
275
* An identifier that occurs in a type-only import.
275
276
*
276
- * These may declare a type and/or a namespace, but for compatibility with our AST,
277
- * must be emitted as a VarDecl (with no variable binding).
277
+ * <p> These may declare a type and/or a namespace, but for compatibility with our AST, must be
278
+ * emitted as a VarDecl (with no variable binding).
278
279
*/
279
280
TYPE_ONLY_IMPORT ,
280
281
281
282
/**
282
283
* An identifier that occurs in a type-only export.
283
284
*
284
- * These may refer to a type and/or a namespace, but for compatibility with our AST,
285
- * must be emitted as an ExportVarAccess (with no variable binding).
285
+ * <p> These may refer to a type and/or a namespace, but for compatibility with our AST, must be
286
+ * emitted as an ExportVarAccess (with no variable binding).
286
287
*/
287
288
TYPE_ONLY_EXPORT ,
288
289
@@ -302,8 +303,8 @@ public enum IdContext {
302
303
EXPORT ,
303
304
304
305
/**
305
- * An identifier that occurs as a qualified name in a default export expression, such as
306
- * <code>A< /code> in <code>export default A.B</code>.
306
+ * An identifier that occurs as a qualified name in a default export expression, such as <code>A
307
+ * </code> in <code>export default A.B</code>.
307
308
*
308
309
* <p>This acts like {@link #EXPORT}, except it cannot refer to a type (i.e. it must be a
309
310
* variable and/or a namespace).
@@ -314,8 +315,8 @@ public enum IdContext {
314
315
* True if this occurs as part of a type annotation, i.e. it is {@link #TYPE_BIND} or {@link
315
316
* #TYPE_DECL}, {@link #TYPE_LABEL}, {@link #VAR_IN_TYPE_BIND}, or {@link #NAMESPACE_BIND}.
316
317
*
317
- * <p>Does not hold for {@link #VAR_AND_TYPE_DECL}, {@link #TYPE_ONLY_IMPORT}, or @{link {@link #TYPE_ONLY_EXPORT}
318
- * as these do not occur in type annotations.
318
+ * <p>Does not hold for {@link #VAR_AND_TYPE_DECL}, {@link #TYPE_ONLY_IMPORT}, or @{link {@link
319
+ * #TYPE_ONLY_EXPORT} as these do not occur in type annotations.
319
320
*/
320
321
public boolean isInsideType () {
321
322
return this == TYPE_BIND
@@ -577,7 +578,9 @@ public Label visit(Literal nd, Context c) {
577
578
Matcher m = TemplateEngines .TEMPLATE_TAGS .matcher (nd .getRaw ());
578
579
int offset = nd .getLoc ().getStart ().getOffset ();
579
580
while (m .find ()) {
580
- Label locationLbl = TemplateEngines .makeLocation (lexicalExtractor .getTextualExtractor (), offset + m .start (), offset + m .end ());
581
+ Label locationLbl =
582
+ TemplateEngines .makeLocation (
583
+ lexicalExtractor .getTextualExtractor (), offset + m .start (), offset + m .end ());
581
584
trapwriter .addTuple ("expr_contains_template_tag_location" , key , locationLbl );
582
585
}
583
586
}
@@ -716,7 +719,8 @@ public Label visit(Program nd, Context c) {
716
719
+ locationManager .getStartLine ()
717
720
+ ","
718
721
+ locationManager .getStartColumn ());
719
- Scope moduleScope = scopeManager .enterScope (ScopeKind .MODULE , moduleScopeKey , toplevelLabel );
722
+ Scope moduleScope =
723
+ scopeManager .enterScope (ScopeKind .MODULE , moduleScopeKey , toplevelLabel );
720
724
if (sourceType .hasNoGlobalScope ()) {
721
725
scopeManager .setImplicitVariableScope (moduleScope );
722
726
}
@@ -1178,9 +1182,7 @@ public Label visit(Property nd, Context c) {
1178
1182
return propkey ;
1179
1183
}
1180
1184
1181
- /**
1182
- * Extracts the string value of <code>expr</code> as an HTML snippet.
1183
- */
1185
+ /** Extracts the string value of <code>expr</code> as an HTML snippet. */
1184
1186
private void extractStringValueAsHtml (Expression expr , Label exprLabel ) {
1185
1187
TextualExtractor textualExtractor = lexicalExtractor .getTextualExtractor ();
1186
1188
if (textualExtractor .isSnippet ()) {
@@ -1193,16 +1195,21 @@ private void extractStringValueAsHtml(Expression expr, Label exprLabel) {
1193
1195
String source = sourceAndOffset .fst ();
1194
1196
SourceLocation loc = expr .getLoc ();
1195
1197
Path originalFile = textualExtractor .getExtractedFile ().toPath ();
1196
- Path vfile = originalFile .resolveSibling (originalFile .getFileName ().toString () + "." + loc .getStart ().getLine () + "." + loc .getStart ().getColumn () + ".html" );
1197
- SourceMap sourceMap = textualExtractor .getSourceMap ().offsetBy (loc .getStart ().getOffset (), sourceAndOffset .snd ());
1198
- TextualExtractor innerTextualExtractor = new TextualExtractor (
1199
- trapwriter ,
1200
- locationManager ,
1201
- source ,
1202
- false ,
1203
- getMetrics (),
1204
- vfile .toFile (),
1205
- sourceMap );
1198
+ Path vfile =
1199
+ originalFile .resolveSibling (
1200
+ originalFile .getFileName ().toString ()
1201
+ + "."
1202
+ + loc .getStart ().getLine ()
1203
+ + "."
1204
+ + loc .getStart ().getColumn ()
1205
+ + ".html" );
1206
+ SourceMap sourceMap =
1207
+ textualExtractor
1208
+ .getSourceMap ()
1209
+ .offsetBy (loc .getStart ().getOffset (), sourceAndOffset .snd ());
1210
+ TextualExtractor innerTextualExtractor =
1211
+ new TextualExtractor (
1212
+ trapwriter , locationManager , source , false , getMetrics (), vfile .toFile (), sourceMap );
1206
1213
HTMLExtractor html = HTMLExtractor .forEmbeddedHtml (config );
1207
1214
List <Label > rootNodes = html .extractEx (innerTextualExtractor ).fst ();
1208
1215
int rootNodeIndex = 0 ;
@@ -1212,7 +1219,7 @@ private void extractStringValueAsHtml(Expression expr, Label exprLabel) {
1212
1219
}
1213
1220
1214
1221
private String tryGetIdentifierName (Expression e ) {
1215
- return e instanceof Identifier ? ((Identifier )e ).getName () : null ;
1222
+ return e instanceof Identifier ? ((Identifier ) e ).getName () : null ;
1216
1223
}
1217
1224
1218
1225
private Pair <String , OffsetTranslation > tryGetStringValueFromExpression (Expression e ) {
@@ -1232,7 +1239,8 @@ private Pair<String, OffsetTranslation> tryGetStringValueFromExpression(Expressi
1232
1239
return null ;
1233
1240
}
1234
1241
TemplateElement element = lit .getQuasis ().get (0 );
1235
- return Pair .make ((String ) element .getCooked (), makeStringLiteralOffsets ("`" + element .getRaw () + "`" ));
1242
+ return Pair .make (
1243
+ (String ) element .getCooked (), makeStringLiteralOffsets ("`" + element .getRaw () + "`" ));
1236
1244
}
1237
1245
return null ;
1238
1246
}
@@ -1677,9 +1685,9 @@ public Label visit(ExportNamedDeclaration nd, Context c) {
1677
1685
visit (nd .getDeclaration (), lbl , -1 );
1678
1686
visit (nd .getSource (), lbl , -2 );
1679
1687
IdContext childContext =
1680
- nd .hasSource () ? IdContext . LABEL :
1681
- nd . hasTypeKeyword () ? IdContext .TYPE_ONLY_EXPORT :
1682
- IdContext .EXPORT ;
1688
+ nd .hasSource ()
1689
+ ? IdContext .LABEL
1690
+ : nd . hasTypeKeyword () ? IdContext . TYPE_ONLY_EXPORT : IdContext .EXPORT ;
1683
1691
visitAll (nd .getSpecifiers (), lbl , childContext , 0 );
1684
1692
if (nd .hasTypeKeyword ()) {
1685
1693
trapwriter .addTuple ("has_type_keyword" , lbl );
@@ -1699,7 +1707,10 @@ public Label visit(ExportSpecifier nd, Context c) {
1699
1707
public Label visit (ImportDeclaration nd , Context c ) {
1700
1708
Label lbl = super .visit (nd , c );
1701
1709
visit (nd .getSource (), lbl , -1 );
1702
- IdContext childContext = nd .hasTypeKeyword () ? IdContext .TYPE_ONLY_IMPORT : IdContext .VAR_AND_TYPE_AND_NAMESPACE_DECL ;
1710
+ IdContext childContext =
1711
+ nd .hasTypeKeyword ()
1712
+ ? IdContext .TYPE_ONLY_IMPORT
1713
+ : IdContext .VAR_AND_TYPE_AND_NAMESPACE_DECL ;
1703
1714
visitAll (nd .getSpecifiers (), lbl , childContext , 0 );
1704
1715
emitNodeSymbol (nd , lbl );
1705
1716
if (nd .hasTypeKeyword ()) {
@@ -2235,10 +2246,14 @@ public Label visit(AngularPipeRef nd, Context c) {
2235
2246
2236
2247
@ Override
2237
2248
public Label visit (GeneratedCodeExpr nd , Context c ) {
2238
- Label key = super .visit (nd , c );
2239
- Label templateLbl = TemplateEngines .makeLocation (lexicalExtractor .getTextualExtractor (), nd .getLoc ().getStart ().getOffset (), nd .getLoc ().getEnd ().getOffset ());
2240
- trapwriter .addTuple ("expr_contains_template_tag_location" , key , templateLbl );
2241
- return key ;
2249
+ Label key = super .visit (nd , c );
2250
+ Label templateLbl =
2251
+ TemplateEngines .makeLocation (
2252
+ lexicalExtractor .getTextualExtractor (),
2253
+ nd .getLoc ().getStart ().getOffset (),
2254
+ nd .getLoc ().getEnd ().getOffset ());
2255
+ trapwriter .addTuple ("expr_contains_template_tag_location" , key , templateLbl );
2256
+ return key ;
2242
2257
}
2243
2258
}
2244
2259
0 commit comments