From 295a143585bdef16f407d2372c6756232d382774 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Fri, 28 Oct 2022 09:17:01 +0000 Subject: [PATCH] Fix special character of template literal Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5YATR?from=project-issue Test: test262 of es2abc, parser, compiler Signed-off-by: zhangrengao Change-Id: I8a302e2bc75a732e5661389112436bd1424431c6 --- es2panda/ir/expressions/templateLiteral.cpp | 4 ++-- .../literals/special-character-expected.txt | 9 +++++++++ .../js/language/literals/special-character.js | 13 +++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 es2panda/test/compiler/js/language/literals/special-character-expected.txt create mode 100644 es2panda/test/compiler/js/language/literals/special-character.js diff --git a/es2panda/ir/expressions/templateLiteral.cpp b/es2panda/ir/expressions/templateLiteral.cpp index 1a66c3b81a..202b21dd3b 100644 --- a/es2panda/ir/expressions/templateLiteral.cpp +++ b/es2panda/ir/expressions/templateLiteral.cpp @@ -43,7 +43,7 @@ void TemplateLiteral::Compile(compiler::PandaGen *pg) const auto quasisIt = quasis_.begin(); auto expressionIt = expressions_.begin(); - pg->LoadAccumulatorString(this, (*quasisIt)->Raw()); + pg->LoadAccumulatorString(this, (*quasisIt)->Cooked()); quasisIt++; @@ -58,7 +58,7 @@ void TemplateLiteral::Compile(compiler::PandaGen *pg) const if (isQuais) { pg->StoreAccumulator(*quasisIt, lhs); - pg->LoadAccumulatorString(this, (*quasisIt)->Raw()); + pg->LoadAccumulatorString(this, (*quasisIt)->Cooked()); node = *quasisIt; quasisIt++; diff --git a/es2panda/test/compiler/js/language/literals/special-character-expected.txt b/es2panda/test/compiler/js/language/literals/special-character-expected.txt new file mode 100644 index 0000000000..c54b773db3 --- /dev/null +++ b/es2panda/test/compiler/js/language/literals/special-character-expected.txt @@ -0,0 +1,9 @@ +test + +test + +test +test' +test" +test? +test diff --git a/es2panda/test/compiler/js/language/literals/special-character.js b/es2panda/test/compiler/js/language/literals/special-character.js new file mode 100644 index 0000000000..7ced4fee80 --- /dev/null +++ b/es2panda/test/compiler/js/language/literals/special-character.js @@ -0,0 +1,13 @@ +function test() { + let a = "test\n"; + print(a); + let b = "test"; + print(`${b}\n`); + print(`${b}\t`); + print(`${b}\'`); + print(`${b}\"`); + print(`${b}\?`); + print(`${b}\0`); +} + +test(); \ No newline at end of file -- Gitee