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"] ) 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..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 @@ -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