mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
JS: Capitalize enum members in ScopeKind and TopLevelKind
This commit is contained in:
@@ -704,7 +704,7 @@ public class ASTExtractor {
|
||||
+ locationManager.getStartLine()
|
||||
+ ","
|
||||
+ locationManager.getStartColumn());
|
||||
Scope moduleScope = scopeManager.enterScope(ScopeKind.module, moduleScopeKey, toplevelLabel);
|
||||
Scope moduleScope = scopeManager.enterScope(ScopeKind.MODULE, moduleScopeKey, toplevelLabel);
|
||||
if (sourceType.hasNoGlobalScope()) {
|
||||
scopeManager.setImplicitVariableScope(moduleScope);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class HTMLExtractor implements IExtractor {
|
||||
source = source.replace("<![CDATA[", " ").replace("]]>", " ");
|
||||
if (!source.trim().isEmpty()) {
|
||||
extractSnippet(
|
||||
TopLevelKind.inlineScript,
|
||||
TopLevelKind.INLINE_SCRIPT,
|
||||
config.withSourceType(sourceType),
|
||||
scopeManager,
|
||||
textualExtractor,
|
||||
@@ -97,7 +97,7 @@ public class HTMLExtractor implements IExtractor {
|
||||
int valueStart = attr.getValueSegment().getBegin();
|
||||
if (JS_ATTRIBUTE.matcher(attr.getName()).matches()) {
|
||||
extractSnippet(
|
||||
TopLevelKind.eventHandler,
|
||||
TopLevelKind.EVENT_HANDLER,
|
||||
config,
|
||||
scopeManager,
|
||||
textualExtractor,
|
||||
@@ -118,7 +118,7 @@ public class HTMLExtractor implements IExtractor {
|
||||
}
|
||||
}
|
||||
extractSnippet(
|
||||
TopLevelKind.angularTemplate,
|
||||
TopLevelKind.ANGULAR_TEMPLATE,
|
||||
config.withSourceType(SourceType.ANGULAR_TEMPLATE),
|
||||
scopeManager,
|
||||
textualExtractor,
|
||||
@@ -130,7 +130,7 @@ public class HTMLExtractor implements IExtractor {
|
||||
} else if (source.startsWith("javascript:")) {
|
||||
source = source.substring(11);
|
||||
extractSnippet(
|
||||
TopLevelKind.javascriptUrl,
|
||||
TopLevelKind.JAVASCRIPT_URL,
|
||||
config,
|
||||
scopeManager,
|
||||
textualExtractor,
|
||||
|
||||
@@ -4,23 +4,23 @@ package com.semmle.js.extractor;
|
||||
* A kind of scope, corresponding to the <code>@scope</code> type in the dbscheme.
|
||||
*/
|
||||
public enum ScopeKind {
|
||||
global(0),
|
||||
function(1),
|
||||
catch_(2),
|
||||
module(3),
|
||||
block(4),
|
||||
for_(5),
|
||||
forIn(6),
|
||||
comprehensionBlock(7),
|
||||
classExpr(8),
|
||||
namespace(9),
|
||||
classDecl(10),
|
||||
interface_(11),
|
||||
typeAlias(12),
|
||||
mappedType(13),
|
||||
enum_(14),
|
||||
externalModule(15),
|
||||
conditionalType(16);
|
||||
GLOBAL(0),
|
||||
FUNCTION(1),
|
||||
CATCH(2),
|
||||
MODULE(3),
|
||||
BLOCK(4),
|
||||
FOR(5),
|
||||
FOR_IN(6),
|
||||
COMPREHENSION_BLOCK(7),
|
||||
CLASS_EXPR(8),
|
||||
NAMESPACE(9),
|
||||
CLASS_DECL(10),
|
||||
INTERFACE(11),
|
||||
TYPE_ALIAS(12),
|
||||
MAPPED_TYPE(13),
|
||||
ENUM(14),
|
||||
EXTERNAL_MODULE(15),
|
||||
CONDITIONAL_TYPE(16);
|
||||
|
||||
private int value;
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ScopeManager {
|
||||
|
||||
public ScopeManager(TrapWriter trapWriter, ECMAVersion ecmaVersion) {
|
||||
this.trapWriter = trapWriter;
|
||||
this.toplevelScope = enterScope(ScopeKind.global, trapWriter.globalID("global_scope"), null);
|
||||
this.toplevelScope = enterScope(ScopeKind.GLOBAL, trapWriter.globalID("global_scope"), null);
|
||||
this.ecmaVersion = ecmaVersion;
|
||||
this.implicitVariableScope = toplevelScope;
|
||||
}
|
||||
@@ -176,29 +176,29 @@ public class ScopeManager {
|
||||
private static final Map<String, ScopeKind> scopeKinds = new LinkedHashMap<String, ScopeKind>();
|
||||
|
||||
static {
|
||||
scopeKinds.put("Program", ScopeKind.global);
|
||||
scopeKinds.put("FunctionDeclaration", ScopeKind.function);
|
||||
scopeKinds.put("FunctionExpression", ScopeKind.function);
|
||||
scopeKinds.put("ArrowFunctionExpression", ScopeKind.function);
|
||||
scopeKinds.put("CatchClause", ScopeKind.catch_);
|
||||
scopeKinds.put("Module", ScopeKind.module);
|
||||
scopeKinds.put("BlockStatement", ScopeKind.block);
|
||||
scopeKinds.put("SwitchStatement", ScopeKind.block);
|
||||
scopeKinds.put("ForStatement", ScopeKind.for_);
|
||||
scopeKinds.put("ForInStatement", ScopeKind.forIn);
|
||||
scopeKinds.put("ForOfStatement", ScopeKind.forIn);
|
||||
scopeKinds.put("ComprehensionBlock", ScopeKind.comprehensionBlock);
|
||||
scopeKinds.put("LetStatement", ScopeKind.block);
|
||||
scopeKinds.put("LetExpression", ScopeKind.block);
|
||||
scopeKinds.put("ClassExpression", ScopeKind.classExpr);
|
||||
scopeKinds.put("NamespaceDeclaration", ScopeKind.namespace);
|
||||
scopeKinds.put("ClassDeclaration", ScopeKind.classDecl);
|
||||
scopeKinds.put("InterfaceDeclaration", ScopeKind.interface_);
|
||||
scopeKinds.put("TypeAliasDeclaration", ScopeKind.typeAlias);
|
||||
scopeKinds.put("MappedTypeExpr", ScopeKind.mappedType);
|
||||
scopeKinds.put("EnumDeclaration", ScopeKind.enum_);
|
||||
scopeKinds.put("ExternalModuleDeclaration", ScopeKind.externalModule);
|
||||
scopeKinds.put("ConditionalTypeExpr", ScopeKind.conditionalType);
|
||||
scopeKinds.put("Program", ScopeKind.GLOBAL);
|
||||
scopeKinds.put("FunctionDeclaration", ScopeKind.FUNCTION);
|
||||
scopeKinds.put("FunctionExpression", ScopeKind.FUNCTION);
|
||||
scopeKinds.put("ArrowFunctionExpression", ScopeKind.FUNCTION);
|
||||
scopeKinds.put("CatchClause", ScopeKind.CATCH);
|
||||
scopeKinds.put("Module", ScopeKind.MODULE);
|
||||
scopeKinds.put("BlockStatement", ScopeKind.BLOCK);
|
||||
scopeKinds.put("SwitchStatement", ScopeKind.BLOCK);
|
||||
scopeKinds.put("ForStatement", ScopeKind.FOR);
|
||||
scopeKinds.put("ForInStatement", ScopeKind.FOR_IN);
|
||||
scopeKinds.put("ForOfStatement", ScopeKind.FOR_IN);
|
||||
scopeKinds.put("ComprehensionBlock", ScopeKind.COMPREHENSION_BLOCK);
|
||||
scopeKinds.put("LetStatement", ScopeKind.BLOCK);
|
||||
scopeKinds.put("LetExpression", ScopeKind.BLOCK);
|
||||
scopeKinds.put("ClassExpression", ScopeKind.CLASS_EXPR);
|
||||
scopeKinds.put("NamespaceDeclaration", ScopeKind.NAMESPACE);
|
||||
scopeKinds.put("ClassDeclaration", ScopeKind.CLASS_DECL);
|
||||
scopeKinds.put("InterfaceDeclaration", ScopeKind.INTERFACE);
|
||||
scopeKinds.put("TypeAliasDeclaration", ScopeKind.TYPE_ALIAS);
|
||||
scopeKinds.put("MappedTypeExpr", ScopeKind.MAPPED_TYPE);
|
||||
scopeKinds.put("EnumDeclaration", ScopeKind.ENUM);
|
||||
scopeKinds.put("ExternalModuleDeclaration", ScopeKind.EXTERNAL_MODULE);
|
||||
scopeKinds.put("ConditionalTypeExpr", ScopeKind.CONDITIONAL_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ScriptExtractor implements IExtractor {
|
||||
LoCInfo loc;
|
||||
try {
|
||||
Pair<Label, LoCInfo> res =
|
||||
new JSExtractor(config).extract(textualExtractor, source, TopLevelKind.script, scopeManager);
|
||||
new JSExtractor(config).extract(textualExtractor, source, TopLevelKind.SCRIPT, scopeManager);
|
||||
toplevelLabel = res.fst();
|
||||
loc = res.snd();
|
||||
} catch (ParseError e) {
|
||||
|
||||
@@ -4,11 +4,11 @@ package com.semmle.js.extractor;
|
||||
* A kind of top-level, corresponding to the <code>@toplevel</code> type in the dbscheme.
|
||||
*/
|
||||
public enum TopLevelKind {
|
||||
script(0),
|
||||
inlineScript(1),
|
||||
eventHandler(2),
|
||||
javascriptUrl(3),
|
||||
angularTemplate(4);
|
||||
SCRIPT(0),
|
||||
INLINE_SCRIPT(1),
|
||||
EVENT_HANDLER(2),
|
||||
JAVASCRIPT_URL(3),
|
||||
ANGULAR_TEMPLATE(4);
|
||||
|
||||
private int value;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TypeScriptExtractor implements IExtractor {
|
||||
try {
|
||||
FileSnippet snippet = state.getSnippets().get(sourceFile.toPath());
|
||||
SourceType sourceType = snippet != null ? snippet.getSourceType() : jsExtractor.establishSourceType(source, false);
|
||||
TopLevelKind toplevelKind = snippet != null ? snippet.getTopLevelKind() : TopLevelKind.script;
|
||||
TopLevelKind toplevelKind = snippet != null ? snippet.getTopLevelKind() : TopLevelKind.SCRIPT;
|
||||
return jsExtractor.extract(textualExtractor, source, toplevelKind, scopeManager, sourceType, res).snd();
|
||||
} catch (ParseError e) {
|
||||
e.setPosition(locationManager.translatePosition(e.getPosition()));
|
||||
|
||||
Reference in New Issue
Block a user