Skip to content

Commit 159dd57

Browse files
committed
Add support for ?. token
1 parent e4e298a commit 159dd57

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

pom.xml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (C) 2000 - 2019 Silverpeas
4+
Copyright (C) 2000 - 2024 Silverpeas
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU Affero General Public License as
@@ -31,7 +31,7 @@
3131
<packaging>jar</packaging>
3232
<groupId>org.silverpeas</groupId>
3333
<artifactId>silverpeas-ui-compressor</artifactId>
34-
<version>2.5</version>
34+
<version>2.6-SNAPSHOT</version>
3535
<name>UI Compressor for Silverpeas's projects</name>
3636
<description>
3737
This compressor is a JavaScript compressor which, in addition to removing comments and white-spaces, obfuscates local variables using the smallest possible variable name. This obfuscation is safe, even when using constructs such as 'eval' or 'with' (although the compression is not optimal in those cases).
@@ -50,7 +50,7 @@
5050
<id>Silverpeas</id>
5151
<layout>default</layout>
5252
<name>Silverpeas Repository</name>
53-
<url>http://www.silverpeas.org/nexus/content/groups/silverpeas</url>
53+
<url>https://nexus3.silverpeas.org/repository/silverpeas</url>
5454
<releases>
5555
<enabled>true</enabled>
5656
</releases>
@@ -65,13 +65,13 @@
6565
<id>silverpeas</id>
6666
<name>Repository Silverpeas</name>
6767
<layout>default</layout>
68-
<url>http://www.silverpeas.org/nexus/content/repositories/releases/</url>
68+
<url>https://nexus3.silverpeas.org/repository/releases/</url>
6969
</repository>
7070
<snapshotRepository>
7171
<id>silverpeas-snapshots</id>
7272
<name>Snapshots Repository Silverpeas</name>
7373
<layout>default</layout>
74-
<url>http://www.silverpeas.org/nexus/content/repositories/snapshots/</url>
74+
<url>https://nexus3.silverpeas.org/repository/snapshots/</url>
7575
</snapshotRepository>
7676
<site>
7777
<id>silverpeas_repository</id>
@@ -81,7 +81,7 @@
8181

8282
<properties>
8383
<!-- property used by the CI to both deploy a build version and release the next stable version -->
84-
<next.release>2.5</next.release>
84+
<next.release>2.6</next.release>
8585
</properties>
8686

8787
<build>
@@ -112,8 +112,8 @@
112112
<artifactId>maven-compiler-plugin</artifactId>
113113
<version>3.8.0</version>
114114
<configuration>
115-
<source>1.8</source>
116-
<target>1.8</target>
115+
<source>11</source>
116+
<target>11</target>
117117
<encoding>UTF-8</encoding>
118118
<showDeprecation>true</showDeprecation>
119119
</configuration>
@@ -188,7 +188,7 @@
188188
<plugin>
189189
<groupId>org.apache.maven.plugins</groupId>
190190
<artifactId>maven-antrun-plugin</artifactId>
191-
<version>1.8</version>
191+
<version>3.1.0</version>
192192
</plugin>
193193
</plugins>
194194
</pluginManagement>
@@ -210,15 +210,6 @@
210210
<plugin>
211211
<groupId>org.apache.maven.plugins</groupId>
212212
<artifactId>maven-antrun-plugin</artifactId>
213-
<dependencies>
214-
<dependency>
215-
<groupId>com.sun</groupId>
216-
<artifactId>tools</artifactId>
217-
<version>1.5.0</version>
218-
<scope>system</scope>
219-
<systemPath>${java.home}/../lib/tools.jar</systemPath>
220-
</dependency>
221-
</dependencies>
222213
<executions>
223214
<execution>
224215
<phase>package</phase>

src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class JavaScriptCompressor {
9999
literals.put(new Integer(Token.LB), "[");
100100
literals.put(new Integer(Token.RB), "]");
101101
literals.put(new Integer(Token.DOT), ".");
102+
literals.put(new Integer(Token.CONDITIONAL_DOT), "?.");
102103
literals.put(new Integer(Token.NEW), "new ");
103104
literals.put(new Integer(Token.DELPROP), "delete ");
104105
literals.put(new Integer(Token.IF), "if");
@@ -375,6 +376,7 @@ private static void processStringLiterals(ArrayList tokens, boolean merge) {
375376
if (i < length - 2) {
376377
JavaScriptToken nextNextToken = (JavaScriptToken) tokens.get(i + 2);
377378
if (nextNextToken.getType() == Token.DOT ||
379+
nextNextToken.getType() == Token.CONDITIONAL_DOT ||
378380
nextNextToken.getType() == Token.LB) {
379381
i += 3;
380382
continue;
@@ -877,6 +879,7 @@ private void parseExpression() {
877879

878880
if ((offset < 2 ||
879881
(getToken(-2).getType() != Token.DOT &&
882+
getToken(-2).getType() != Token.CONDITIONAL_DOT &&
880883
getToken(-2).getType() != Token.GET &&
881884
getToken(-2).getType() != Token.SET)) &&
882885
getToken(0).getType() != Token.OBJECTLIT) {
@@ -1028,7 +1031,8 @@ private void parseScope(ScriptOrFnScope scope) {
10281031

10291032
} else if (mode == CHECKING_SYMBOL_TREE) {
10301033

1031-
if ((offset < 2 || getToken(-2).getType() != Token.DOT) &&
1034+
if ((offset < 2 || (getToken(-2).getType() != Token.DOT &&
1035+
getToken(-2).getType() != Token.CONDITIONAL_DOT)) &&
10321036
getToken(0).getType() != Token.OBJECTLIT) {
10331037

10341038
identifier = getIdentifier(symbol, scope);
@@ -1132,7 +1136,8 @@ private StringBuffer printSymbolTree(int linebreakpos, boolean preserveAllSemiCo
11321136

11331137
case Token.NAME:
11341138

1135-
if (offset >= 2 && getToken(-2).getType() == Token.DOT ||
1139+
if (offset >= 2 && (getToken(-2).getType() == Token.DOT ||
1140+
getToken(-2).getType() == Token.CONDITIONAL_DOT) ||
11361141
getToken(0).getType() == Token.OBJECTLIT) {
11371142

11381143
result.append(symbol);

src/org/mozilla/javascript/Decompiler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@ else if (nextToken == Token.NAME) {
498498
}
499499
break;
500500
}
501+
502+
case Token.CONDITIONAL_DOT:
503+
result.append("?.");
504+
break;
505+
501506
case Token.DOT:
502507
result.append('.');
503508
break;

src/org/mozilla/javascript/Parser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,7 @@ private Node memberExprTail(boolean allowCallSyntax, Node pn)
19481948
switch (tt) {
19491949

19501950
case Token.DOT:
1951+
case Token.CONDITIONAL_DOT:
19511952
case Token.DOTDOT:
19521953
{
19531954
int memberTypeFlags;

src/org/mozilla/javascript/Token.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,9 @@ public class Token
247247
CONDCOMMENT = 160, // JScript conditional comment
248248
KEEPCOMMENT = 161, // /*! ... */ comment
249249

250-
LAST_TOKEN = 162;
250+
CONDITIONAL_DOT = 162, // / member operator if defined object (?.)
251+
252+
LAST_TOKEN = 163;
251253

252254
public static String name(int token)
253255
{
@@ -363,6 +365,7 @@ public static String name(int token)
363365
case INC: return "INC";
364366
case DEC: return "DEC";
365367
case DOT: return "DOT";
368+
case CONDITIONAL_DOT: return "CONDITIONAL_DOT";
366369
case FUNCTION: return "FUNCTION";
367370
case EXPORT: return "EXPORT";
368371
case IMPORT: return "IMPORT";

src/org/mozilla/javascript/TokenStream.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ final int getToken() throws IOException
576576
case '(': return Token.LP;
577577
case ')': return Token.RP;
578578
case ',': return Token.COMMA;
579-
case '?': return Token.HOOK;
579+
case '?':
580+
if (matchChar('.')) {
581+
return Token.CONDITIONAL_DOT;
582+
}
583+
return Token.HOOK;
580584
case ':':
581585
if (matchChar(':')) {
582586
return Token.COLONCOLON;

0 commit comments

Comments
 (0)