Skip to content

Commit 5b999c9

Browse files
committed
Code cleanup
1 parent 1e46893 commit 5b999c9

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

rhino/src/main/java/org/mozilla/javascript/IRFactory.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ private Node transformArrayComp(ArrayComprehension node) {
279279
// createName(tmp1)
280280
// }
281281

282-
int lineno = node.getLineno();
283-
Scope scopeNode = parser.createScopeNode(Token.ARRAYCOMP, lineno);
282+
int lineno = node.getLineno(), column = node.getColumn();
283+
Scope scopeNode = parser.createScopeNode(Token.ARRAYCOMP, lineno, column);
284284
String arrayName = parser.currentScriptOrFn.getNextTempName();
285285
parser.pushScope(scopeNode);
286286
try {
@@ -370,7 +370,8 @@ private Node arrayCompTransformHelper(ArrayComprehension node, String arrayName)
370370
Scope loop =
371371
createLoopNode(
372372
null, // no label
373-
acl.getLineno());
373+
acl.getLineno(),
374+
acl.getColumn());
374375
parser.pushScope(loop);
375376
pushed++;
376377
body =
@@ -658,6 +659,7 @@ private Node transformFunction(FunctionNode fn) {
658659
private Node transformFunctionCall(FunctionCall node) {
659660
Node call = createCallOrNew(Token.CALL, transform(node.getTarget()));
660661
call.setLineno(node.getLineno());
662+
call.setColumn(node.getColumn());
661663
List<AstNode> args = node.getArguments();
662664
for (int i = 0; i < args.size(); i++) {
663665
AstNode arg = args.get(i);
@@ -716,6 +718,7 @@ private Node transformGenExpr(GeneratorExpression node) {
716718

717719
Node call = createCallOrNew(Token.CALL, pn);
718720
call.setLineno(node.getLineno());
721+
call.setLineno(node.getColumn());
719722
return call;
720723
}
721724

@@ -778,7 +781,8 @@ private Node genExprTransformHelper(GeneratorExpression node) {
778781
Scope loop =
779782
createLoopNode(
780783
null, // no label
781-
acl.getLineno());
784+
acl.getLineno(),
785+
acl.getColumn());
782786
parser.pushScope(loop);
783787
pushed++;
784788
body =
@@ -823,8 +827,8 @@ private Node transformInfix(InfixExpression node) {
823827
// createBinary
824828
boolean nodeCreated = (binaryNode != left) && (binaryNode != right);
825829
if (nodeCreated) {
826-
binaryNode.setColumn(node.getColumn());
827830
binaryNode.setLineno(node.getLineno());
831+
binaryNode.setColumn(node.getColumn());
828832
}
829833

830834
return binaryNode;
@@ -869,6 +873,7 @@ private Node transformName(Name node) {
869873
private Node transformNewExpr(NewExpression node) {
870874
Node nx = createCallOrNew(Token.NEW, transform(node.getTarget()));
871875
nx.setLineno(node.getLineno());
876+
nx.setColumn(node.getColumn());
872877
List<AstNode> args = node.getArguments();
873878
for (int i = 0; i < args.size(); i++) {
874879
AstNode arg = args.get(i);
@@ -893,8 +898,8 @@ private Node transformObjectLiteral(ObjectLiteral node) {
893898
// stages don't need to know about object literals.
894899
List<ObjectProperty> elems = node.getElements();
895900
Node object = new Node(Token.OBJECTLIT);
896-
object.setColumn(node.getColumn());
897901
object.setLineno(node.getLineno());
902+
object.setColumn(node.getColumn());
898903
Object[] properties;
899904
if (elems.isEmpty()) {
900905
properties = ScriptRuntime.emptyArgs;
@@ -968,6 +973,7 @@ private Node transformTemplateLiteral(TemplateLiteral node) {
968973
private Node transformTemplateLiteralCall(TaggedTemplateLiteral node) {
969974
Node call = createCallOrNew(Token.CALL, transform(node.getTarget()));
970975
call.setLineno(node.getLineno());
976+
call.setColumn(node.getColumn());
971977
TemplateLiteral templateLiteral = (TemplateLiteral) node.getTemplateLiteral();
972978
List<AstNode> elems = templateLiteral.getElements();
973979
call.addChildToBack(templateLiteral);
@@ -1010,8 +1016,8 @@ private Node transformScript(ScriptNode node) {
10101016

10111017
private Node transformString(StringLiteral node) {
10121018
Node stringNode = Node.newString(node.getValue());
1013-
stringNode.setColumn(node.getColumn());
10141019
stringNode.setLineno(node.getLineno());
1020+
stringNode.setColumn(node.getColumn());
10151021
return stringNode;
10161022
}
10171023

@@ -1398,8 +1404,8 @@ private static Node initFunction(
13981404
* Create loop node. The code generator will later call
13991405
* createWhile|createDoWhile|createFor|createForIn to finish loop generation.
14001406
*/
1401-
private Scope createLoopNode(Node loopLabel, int lineno) {
1402-
Scope result = parser.createScopeNode(Token.LOOP, lineno);
1407+
private Scope createLoopNode(Node loopLabel, int lineno, int column) {
1408+
Scope result = parser.createScopeNode(Token.LOOP, lineno, column);
14031409
if (loopLabel != null) {
14041410
((Jump) loopLabel).setLoop(result);
14051411
}

rhino/src/main/java/org/mozilla/javascript/Parser.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ private void recordComment(int lineno, int column, String comment) {
346346
currentJsDocComment =
347347
new Comment(ts.tokenBeg, ts.getTokenLength(), ts.commentType, comment);
348348
currentJsDocComment.setLineno(lineno);
349+
currentJsDocComment.setColumn(column);
349350
}
350351
commentNode.setLineno(lineno);
351352
commentNode.setColumn(column);
@@ -683,7 +684,6 @@ private AstNode parseFunctionBody(int type, FunctionNode fnNode) throws IOExcept
683684
++nestingOfFunction;
684685
int pos = ts.tokenBeg;
685686
Block pn = new Block(pos); // starts at LC position
686-
pn.setColumn(columnNumber());
687687

688688
// Function code that is supplied as the arguments to the built-in
689689
// Function, Generator, and AsyncFunction constructors is strict mode code
@@ -694,6 +694,7 @@ private AstNode parseFunctionBody(int type, FunctionNode fnNode) throws IOExcept
694694
inUseStrictDirective = false;
695695

696696
pn.setLineno(lineNumber());
697+
pn.setColumn(columnNumber());
697698
try {
698699
if (isExpressionClosure) {
699700
AstNode returnValue = assignExpr();
@@ -1467,9 +1468,9 @@ private SwitchStatement switchStatement() throws IOException {
14671468
int pos = ts.tokenBeg;
14681469

14691470
SwitchStatement pn = new SwitchStatement(pos);
1470-
if (mustMatchToken(Token.LP, "msg.no.paren.switch", true)) pn.setLp(ts.tokenBeg - pos);
14711471
pn.setLineno(lineNumber());
1472-
pn.setColumn(ts.getTokenColumn(pos));
1472+
pn.setColumn(columnNumber());
1473+
if (mustMatchToken(Token.LP, "msg.no.paren.switch", true)) pn.setLp(ts.tokenBeg - pos);
14731474

14741475
AstNode discriminant = expr(false);
14751476
pn.setExpression(discriminant);
@@ -1553,7 +1554,7 @@ private WhileLoop whileLoop() throws IOException {
15531554
int pos = ts.tokenBeg;
15541555
WhileLoop pn = new WhileLoop(pos);
15551556
pn.setLineno(lineNumber());
1556-
pn.setColumn(ts.getTokenColumn(pos));
1557+
pn.setColumn(columnNumber());
15571558
enterLoop(pn);
15581559
try {
15591560
ConditionData data = condition();
@@ -1575,7 +1576,7 @@ private DoLoop doLoop() throws IOException {
15751576
int pos = ts.tokenBeg, end;
15761577
DoLoop pn = new DoLoop(pos);
15771578
pn.setLineno(lineNumber());
1578-
pn.setColumn(ts.getTokenColumn(pos));
1579+
pn.setColumn(columnNumber());
15791580
enterLoop(pn);
15801581
try {
15811582
AstNode body = getNextStatementAfterInlineComments(pn);
@@ -1876,7 +1877,6 @@ private TryStatement tryStatement() throws IOException {
18761877
catchNode.setIfPosition(guardPos - catchPos);
18771878
}
18781879
catchNode.setParens(lp, rp);
1879-
catchNode.setLineno(catchLineNum);
18801880

18811881
if (mustMatchToken(Token.RC, "msg.no.brace.after.body", true)) tryEnd = ts.tokenEnd;
18821882
catchNode.setLength(tryEnd - catchPos);
@@ -2180,7 +2180,7 @@ private AstNode defaultXmlNamespace() throws IOException {
21802180
consumeToken();
21812181
mustHaveXML();
21822182
setRequiresActivation();
2183-
int lineno = lineNumber(), pos = ts.tokenBeg;
2183+
int lineno = lineNumber(), column = columnNumber(), pos = ts.tokenBeg;
21842184

21852185
if (!(matchToken(Token.NAME, true) && "xml".equals(ts.getString()))) {
21862186
reportError("msg.bad.namespace");
@@ -2197,6 +2197,7 @@ private AstNode defaultXmlNamespace() throws IOException {
21972197
dxmln.setOperator(Token.DEFAULTNAMESPACE);
21982198
dxmln.setOperand(e);
21992199
dxmln.setLineno(lineno);
2200+
dxmln.setColumn(column);
22002201

22012202
ExpressionStatement es = new ExpressionStatement(dxmln, true);
22022203
return es;
@@ -2354,7 +2355,6 @@ private VariableDeclaration variables(int declType, int pos, boolean isStatement
23542355
}
23552356

23562357
VariableInitializer vi = new VariableInitializer(kidPos, end - kidPos);
2357-
vi.setColumn(ts.getTokenColumn(kidPos));
23582358
if (destructuring != null) {
23592359
if (init == null && !inForInit) {
23602360
reportError("msg.destruct.assign.no.init");
@@ -2381,6 +2381,7 @@ private VariableDeclaration variables(int declType, int pos, boolean isStatement
23812381
private AstNode let(boolean isStatement, int pos) throws IOException {
23822382
LetNode pn = new LetNode(pos);
23832383
pn.setLineno(lineNumber());
2384+
pn.setColumn(columnNumber());
23842385
if (mustMatchToken(Token.LP, "msg.no.paren.after.let", true)) pn.setLp(ts.tokenBeg - pos);
23852386
pushScope(pn);
23862387
try {
@@ -2408,6 +2409,7 @@ private AstNode let(boolean isStatement, int pos) throws IOException {
24082409
// let expression in statement context
24092410
ExpressionStatement es = new ExpressionStatement(pn, !insideFunction());
24102411
es.setLineno(pn.getLineno());
2412+
es.setColumn(pn.getColumn());
24112413
return es;
24122414
}
24132415
}
@@ -2871,6 +2873,7 @@ private AstNode xmlInitializer() throws IOException {
28712873

28722874
XmlLiteral pn = new XmlLiteral(pos);
28732875
pn.setLineno(lineNumber());
2876+
pn.setColumn(columnNumber());
28742877

28752878
for (; ; tt = ts.getNextXMLToken()) {
28762879
switch (tt) {
@@ -3423,7 +3426,10 @@ private AstNode primaryExpr() throws IOException {
34233426
consumeToken();
34243427
pos = ts.tokenBeg;
34253428
end = ts.tokenEnd;
3426-
return new KeywordLiteral(pos, end - pos, tt, ts.getTokenColumn(pos));
3429+
KeywordLiteral keywordLiteral = new KeywordLiteral(pos, end - pos, tt);
3430+
keywordLiteral.setLineno(lineNumber());
3431+
keywordLiteral.setColumn(columnNumber());
3432+
return keywordLiteral;
34273433

34283434
case Token.TEMPLATE_LITERAL:
34293435
consumeToken();
@@ -4372,7 +4378,7 @@ Node destructuringAssignmentHelper(
43724378
String tempName,
43734379
AstNode defaultValue,
43744380
Transformer transformer) {
4375-
Scope result = createScopeNode(Token.LETEXPR, left.getLineno());
4381+
Scope result = createScopeNode(Token.LETEXPR, left.getLineno(), left.getColumn());
43764382
result.addChildToFront(new Node(Token.LET, createName(Token.NAME, tempName, right)));
43774383
try {
43784384
pushScope(result);
@@ -4591,12 +4597,13 @@ boolean destructuringObject(
45914597
boolean defaultValuesSetup = false;
45924598

45934599
for (ObjectProperty prop : node.getElements()) {
4594-
int lineno = 0;
4600+
int lineno = 0, column = 0;
45954601
// This function is sometimes called from the IRFactory
45964602
// when executing regression tests, and in those cases the
45974603
// tokenStream isn't set. Deal with it.
45984604
if (ts != null) {
45994605
lineno = lineNumber();
4606+
column = columnNumber();
46004607
}
46014608
AstNode id = prop.getLeft();
46024609

@@ -4618,6 +4625,7 @@ boolean destructuringObject(
46184625
}
46194626

46204627
rightElem.setLineno(lineno);
4628+
rightElem.setColumn(column);
46214629
if (defaultValue != null && !defaultValuesSetup) {
46224630
setupDefaultValues(tempName, parent, defaultValue, setOp, transformer);
46234631
defaultValuesSetup = true;
@@ -4680,10 +4688,11 @@ protected Node createNumber(double number) {
46804688
* @param lineno line number of source
46814689
* @return the created node
46824690
*/
4683-
protected Scope createScopeNode(int token, int lineno) {
4691+
protected Scope createScopeNode(int token, int lineno, int column) {
46844692
Scope scope = new Scope();
46854693
scope.setType(token);
46864694
scope.setLineno(lineno);
4695+
scope.setColumn(column);
46874696
return scope;
46884697
}
46894698

rhino/src/main/java/org/mozilla/javascript/ast/KeywordLiteral.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public KeywordLiteral(int pos, int len, int nodeType) {
3535
setType(nodeType);
3636
}
3737

38-
public KeywordLiteral(int pos, int len, int nodeType, int column) {
39-
this(pos, len, nodeType);
40-
super.setColumn(column);
41-
}
42-
4338
/**
4439
* Sets node token type
4540
*

0 commit comments

Comments
 (0)