From f801b30e70745ec16b7ec4734cf95c1e3e46fd69 Mon Sep 17 00:00:00 2001 From: Bram Stappers Date: Wed, 30 Nov 2016 10:20:56 +0100 Subject: [PATCH 1/3] Added template string token to EcmaScript 5 language definition. --- pmd-javascript/etc/grammar/es5.jj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pmd-javascript/etc/grammar/es5.jj b/pmd-javascript/etc/grammar/es5.jj index a2e558c5d3..688692d61d 100644 --- a/pmd-javascript/etc/grammar/es5.jj +++ b/pmd-javascript/etc/grammar/es5.jj @@ -200,7 +200,16 @@ TOKEN : | "'" "'" + | "`" + + "`" > : NOREGEXP +| + < #BACKTICK_STRING_LITERAL_BODY:( + ("\\" ~[] ) + | (~["`", "\\"]) + )* + > | < #SINGLE_STRING_LITERAL_BODY:( ( "\\" ~[ "\r" , "\n" , "\u2028" , "\u2029"] ) From 1681b052222dfe15ba953b8da5ac1fc3a5e7be22 Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Wed, 30 Nov 2016 10:18:06 +0100 Subject: [PATCH 2/3] Added test case for template strings in Ecmascript. --- .../pmd/cpd/EcmascriptTokenizerTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java index eb3cb2f7cf..690baddeb3 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java @@ -118,4 +118,36 @@ public class EcmascriptTokenizerTest { sb.append( "}" ).append(PMD.EOL); return sb.toString(); } + + @Test + public void testTemplateStrings() throws IOException { + Tokenizer t = new EcmascriptTokenizer(); + SourceCode sourceCode = new SourceCode( new SourceCode.StringCodeLoader( + "export default class DrawLocation extends joint.shapes.basic.Generic {\n" + + " constructor(location: ILocation) {\n" + + " this.markup = `\n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " ${drawIndicators.Check.markup}\n" + + "\n" + + " `;\n" + + " }\n" + + "\n" + + "}") ); + final Tokens tokens = new Tokens(); + t.tokenize(sourceCode, tokens); + final String templateString = "`\n" + + " \n" + + " \n" + + "\n" + + " \n" + + " \n" + + " ${drawIndicators.Check.markup}\n" + + "\n" + + " `"; + assertEquals(templateString, tokens.getTokens().get(24).toString()); + } } \ No newline at end of file From 525542c9fa41b6e0ece38635bc1b26aef4ea9cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Fri, 20 Jan 2017 09:11:04 -0300 Subject: [PATCH 3/3] Checkstyle fixes --- .../java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java index 690baddeb3..6d33e98719 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/EcmascriptTokenizerTest.java @@ -122,7 +122,7 @@ public class EcmascriptTokenizerTest { @Test public void testTemplateStrings() throws IOException { Tokenizer t = new EcmascriptTokenizer(); - SourceCode sourceCode = new SourceCode( new SourceCode.StringCodeLoader( + SourceCode sourceCode = new SourceCode(new SourceCode.StringCodeLoader( "export default class DrawLocation extends joint.shapes.basic.Generic {\n" + " constructor(location: ILocation) {\n" + " this.markup = `\n" @@ -136,7 +136,7 @@ public class EcmascriptTokenizerTest { + " `;\n" + " }\n" + "\n" - + "}") ); + + "}")); final Tokens tokens = new Tokens(); t.tokenize(sourceCode, tokens); final String templateString = "`\n"