瀏覽代碼

pas2js: added option -JoUseStrict

git-svn-id: trunk@38793 -
Mattias Gaertner 7 年之前
父節點
當前提交
0601b437a4

+ 1 - 1
packages/pastojs/src/fppas2js.pp

@@ -312,9 +312,9 @@ Works:
   - COM: property in class, property in interface
   - COM: with interface do
   - COM: for interface in ... do
+  - COM: pass IntfVar to untyped parameter
 
 ToDos:
-- replace let in rtl.js
 - option to disable use strict
 - for i in jsvalue do
 - for i in tjsobject do

+ 17 - 5
packages/pastojs/src/pas2jscompiler.pp

@@ -101,11 +101,12 @@ type
     coKeepNotUsedDeclarationsWPO,
     coSourceMapCreate,
     coSourceMapInclude,
-    coSourceMapXSSIHeader
+    coSourceMapXSSIHeader,
+    coUseStrict
     );
   TP2jsCompilerOptions = set of TP2jsCompilerOption;
 const
-  DefaultP2jsCompilerOptions = [coShowErrors,coSourceMapXSSIHeader];
+  DefaultP2jsCompilerOptions = [coShowErrors,coSourceMapXSSIHeader,coUseStrict];
   coShowAll = [coShowErrors..coShowUsedTools];
   coO1Enable = [coEnumValuesAsNumbers];
   coO1Disable = [coKeepNotUsedPrivates,coKeepNotUsedDeclarationsWPO];
@@ -136,7 +137,8 @@ const
     'Keep not used declarations (WPO)',
     'Create source map',
     'Include Pascal sources in source map',
-    'Prepend XSSI protection )]} to source map'
+    'Prepend XSSI protection )]} to source map',
+    'Use strict'
     );
 
 //------------------------------------------------------------------------------
@@ -786,9 +788,16 @@ end;
 function TPas2jsCompilerFile.
   GetInitialConverterOptions: TPasToJsConverterOptions;
 begin
-  Result:=DefaultPasToJSOptions+[coUseStrict];
+  Result:=DefaultPasToJSOptions;
+
+  if coUseStrict in Compiler.Options then
+    Include(Result,fppas2js.coUseStrict)
+  else
+    Exclude(Result,fppas2js.coUseStrict);
+
   if coEnumValuesAsNumbers in Compiler.Options then
     Include(Result,fppas2js.coEnumNumbers);
+
   if coLowerCase in Compiler.Options then
     Include(Result,fppas2js.coLowerCase)
   else
@@ -3154,8 +3163,10 @@ begin
                 Enable:=c='+';
                 Delete(Identifier,length(Identifier),1);
               end;
-              if CompareText(Identifier,'SearchLikeFPC')=0 then
+              if SameText(Identifier,'SearchLikeFPC') then
                 FileCache.SearchLikeFPC:=Enable
+              else if SameText(Identifier,'UseStrict') then
+                SetOption(coUseStrict,Enable)
               else
                 UnknownParam;
             end;
@@ -3874,6 +3885,7 @@ begin
   l('     -Jm- : disable generating source maps');
   l('   -Jo<x> : Enable or disable extra option. The x is case insensitive:');
   l('     -JoSearchLikeFPC : search source files like FPC, default: search case insensitive.');
+  l('     -JoUseStrict : add "use strict" to modules, default.');
   l('   -Ju<x> : Add <x> to foreign unit paths. Foreign units are not compiled.');
   if PrecompileFormats.Count>0 then
   begin

+ 0 - 1
utils/pas2js/dist/rtl.js

@@ -470,7 +470,6 @@ var rtl = {
   },
 
   addIntf: function (aclass, intf, map){
-    'use strict';
     function jmp(fn){
       if (typeof(fn)==="function"){
         return function(){ return fn.apply(this.$o,arguments); };

+ 1 - 0
utils/pas2js/docs/translation.html

@@ -155,6 +155,7 @@ Put + after a boolean switch option to enable it, - to disable it
      -Jm- : disable generating source maps
    -Jo&lt;x&gt; : Enable or disable extra option. The x is case insensitive:
      -JoSearchLikeFPC : search source files like FPC, default: search case insensitive.
+     -JoUseStrict : add "use strict" to modules, default.
    -Ju&lt;x&gt; : Add &lt;x&gt; to foreign unit paths. Foreign units are not compiled.
   -l      : Write logo
   -MDelphi: Delphi 7 compatibility mode