Merge branch '7.0.x' into clem.pmd7-remove-pmd-eol
This commit is contained in:
@ -4,12 +4,15 @@
|
||||
|
||||
package net.sourceforge.pmd.cpd;
|
||||
|
||||
import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Zev Blut zb@ubit.com
|
||||
*/
|
||||
public class EcmascriptLanguage extends AbstractLanguage {
|
||||
public EcmascriptLanguage() {
|
||||
super("JavaScript", "ecmascript", new EcmascriptTokenizer(), ".js");
|
||||
super(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, new EcmascriptTokenizer(),
|
||||
EcmascriptLanguageModule.EXTENSIONS);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,11 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.ecmascript;
|
||||
|
||||
import static net.sourceforge.pmd.util.CollectionUtil.listOf;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.Language;
|
||||
import net.sourceforge.pmd.lang.LanguageRegistry;
|
||||
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser;
|
||||
@ -14,12 +19,19 @@ import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
|
||||
*/
|
||||
public class EcmascriptLanguageModule extends SimpleLanguageModuleBase {
|
||||
|
||||
public static final String NAME = "Ecmascript";
|
||||
public static final String NAME = "JavaScript";
|
||||
public static final String TERSE_NAME = "ecmascript";
|
||||
@InternalApi
|
||||
public static final List<String> EXTENSIONS = listOf("js");
|
||||
|
||||
public EcmascriptLanguageModule() {
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions("js")
|
||||
.addDefaultVersion("ES6"),
|
||||
super(LanguageMetadata.withId(TERSE_NAME).name(NAME).extensions(EXTENSIONS)
|
||||
.addVersion("3")
|
||||
.addVersion("5")
|
||||
.addVersion("6", "ES6", "ES2015")
|
||||
.addVersion("7", "ES2016")
|
||||
.addVersion("8", "ES2017")
|
||||
.addDefaultVersion("9", "ES2018"),
|
||||
properties -> () -> new EcmascriptParser(properties));
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ import org.mozilla.javascript.ast.ErrorCollector;
|
||||
import org.mozilla.javascript.ast.ParseProblem;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
|
||||
import net.sourceforge.pmd.lang.LanguageVersion;
|
||||
import net.sourceforge.pmd.lang.ast.AstInfo;
|
||||
import net.sourceforge.pmd.lang.ast.FileAnalysisException;
|
||||
import net.sourceforge.pmd.lang.ast.ParseException;
|
||||
@ -30,11 +31,11 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
private AstRoot parseEcmascript(final String sourceCode, final List<ParseProblem> parseProblems) throws ParseException {
|
||||
private AstRoot parseEcmascript(final String sourceCode, final LanguageVersion version, final List<ParseProblem> parseProblems) throws ParseException {
|
||||
final CompilerEnvirons compilerEnvirons = new CompilerEnvirons();
|
||||
compilerEnvirons.setRecordingComments(true);
|
||||
compilerEnvirons.setRecordingLocalJsDocComments(true);
|
||||
compilerEnvirons.setLanguageVersion(Context.VERSION_ES6);
|
||||
compilerEnvirons.setLanguageVersion(determineRhinoLanguageVersion(version));
|
||||
// Scope's don't appear to get set right without this
|
||||
compilerEnvirons.setIdeMode(true);
|
||||
compilerEnvirons.setWarnTrailingComma(true);
|
||||
@ -52,10 +53,19 @@ public final class EcmascriptParser implements net.sourceforge.pmd.lang.ast.Pars
|
||||
return astRoot;
|
||||
}
|
||||
|
||||
private static int determineRhinoLanguageVersion(LanguageVersion version) {
|
||||
switch (version.getVersion()) {
|
||||
case "3": return Context.VERSION_1_5;
|
||||
case "5": return Context.VERSION_1_8;
|
||||
default: return Context.VERSION_ES6;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RootNode parse(ParserTask task) throws FileAnalysisException {
|
||||
final LanguageVersion version = task.getLanguageVersion();
|
||||
final List<ParseProblem> parseProblems = new ArrayList<>();
|
||||
final AstRoot astRoot = parseEcmascript(task.getSourceText(), parseProblems);
|
||||
final AstRoot astRoot = parseEcmascript(task.getSourceText(), version, parseProblems);
|
||||
final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(parseProblems);
|
||||
ASTAstRoot tree = (ASTAstRoot) treeBuilder.build(astRoot);
|
||||
|
||||
|
@ -13,7 +13,7 @@ class LanguageVersionTest extends AbstractLanguageVersionTest {
|
||||
|
||||
static Collection<TestDescriptor> data() {
|
||||
return Arrays.asList(
|
||||
new TestDescriptor(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, "ES6",
|
||||
new TestDescriptor(EcmascriptLanguageModule.NAME, EcmascriptLanguageModule.TERSE_NAME, "9",
|
||||
getLanguage(EcmascriptLanguageModule.NAME).getDefaultVersion()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user