Browse Source

pastojs: fixed quoted string literal

git-svn-id: trunk@41897 -
Mattias Gaertner 6 years ago
parent
commit
1bb2173939
2 changed files with 49 additions and 0 deletions
  1. 39 0
      packages/pastojs/src/fppas2js.pp
  2. 10 0
      packages/pastojs/tests/tcmodules.pas

+ 39 - 0
packages/pastojs/src/fppas2js.pp

@@ -2556,6 +2556,13 @@ var
     Result:=false;
   end;
 
+  procedure HandleEscape;
+  begin
+    inc(MyTokenPos);
+    if (MyTokenPos<=l) and (s[MyTokenPos]>#31) then
+      inc(MyTokenPos);
+  end;
+
 begin
   SetCurTokenString('');
   s:=CurLine;
@@ -2574,6 +2581,8 @@ begin
     if MyTokenPos>l then
       if DoEndOfLine then exit;
     case s[MyTokenPos] of
+    '\':
+      HandleEscape;
     '''':
       begin
       inc(MyTokenPos);
@@ -2581,6 +2590,8 @@ begin
         if MyTokenPos>l then
           Error(nErrOpenString,SErrOpenString);
         case s[MyTokenPos] of
+        '\':
+          HandleEscape;
         '''':
           begin
           inc(MyTokenPos);
@@ -2603,6 +2614,8 @@ begin
         if MyTokenPos>l then
           Error(nErrOpenString,SErrOpenString);
         case s[MyTokenPos] of
+        '\':
+          HandleEscape;
         '"':
           begin
           inc(MyTokenPos);
@@ -2618,6 +2631,32 @@ begin
         end;
       until false;
       end;
+    '`': // template literal
+      begin
+      inc(MyTokenPos);
+      repeat
+        while MyTokenPos>l do
+          if DoEndOfLine then
+            begin
+              writeln('AAA1 TPas2jsPasScanner.ReadNonPascalTillEndToken ',StopAtLineEnd);
+            if not StopAtLineEnd then
+              Error(nErrOpenString,SErrOpenString);
+            exit;
+            end;
+        case s[MyTokenPos] of
+        '\':
+          HandleEscape;
+        '`':
+          begin
+          inc(MyTokenPos);
+          break;
+          end;
+        // Note: template literals can span multiple lines
+        else
+          inc(MyTokenPos);
+        end;
+      until false;
+      end;
     '/':
       begin
       inc(MyTokenPos);

+ 10 - 0
packages/pastojs/tests/tcmodules.pas

@@ -3722,6 +3722,11 @@ begin
   '    // end',
   '    s = ''end'';',
   '    s = "end";',
+  '    s = "foo\"bar";',
+  '    s = ''a\''b'';',
+  '    s =  `${expr}\`-"-''-`;',
+  '    s = `multi',
+  'line`;',
   '  end;',
   'end;',
   'procedure Fly;',
@@ -3742,6 +3747,11 @@ begin
     '  // end',
     '  s = ''end'';',
     '  s = "end";',
+    '  s = "foo\"bar";',
+    '  s = ''a\''b'';',
+    '  s =  `${expr}\`-"-''-`;',
+    '  s = `multi',
+    'line`;',
     '  return Result;',
     '};',
     'this.Fly = function () {',