Переглянути джерело

Added a config flag for type annotations

Franco Castellacci 9 роки тому
батько
коміт
aabeb6c26a
4 змінених файлів з 5 додано та 4 видалено
  1. 1 0
      lib/Common/ConfigFlagsList.h
  2. 1 1
      lib/Parser/Parse.cpp
  3. 2 2
      lib/Parser/Scan.cpp
  4. 1 1
      lib/Parser/Scan.h

+ 1 - 0
lib/Common/ConfigFlagsList.h

@@ -1362,6 +1362,7 @@ FLAGNR(Boolean, TraceAsyncDebugCalls  , "Trace calls to async debugging API (def
 #ifdef TRACK_DISPATCH
 FLAGNR(Boolean, TrackDispatch         , "Save stack traces of where JavascriptDispatch/HostVariant are created", false)
 #endif
+FLAGNR(Boolean, TypeAnnotations, "Enables the usage of type annotations in comments (default: false)", false)
 FLAGNR(Boolean, Verbose               , "Dump details", DEFAULT_CONFIG_Verbose)
 FLAGNR(Boolean, UseFullName           , "Enable fully qualified name", DEFAULT_CONFIG_UseFullName)
 FLAGNR(Boolean, UseFunctionIdForTrace , "Use function id instead of function number for trace output", false)

+ 1 - 1
lib/Parser/Parse.cpp

@@ -3231,7 +3231,7 @@ LFunction :
     pnode = ParsePostfixOperators<buildAST>(pnode, fAllowCall, fInNew, isAsyncExpr, &fCanAssign, &term, pfIsDotOrIndex);
 
     //FCASTE: after parsing a term, check if there is a type annotation and parse it
-    if (m_token.tk == tkTypeAnnBegin)
+    if (Js::Configuration::Global.flags.TypeAnnotations && m_token.tk == tkTypeAnnBegin)
     {
         m_pscan->SetScanState(Scanner_t::ScanState::ScanStateTypeAnnotationMiddle);
         m_pscan->Scan();

+ 2 - 2
lib/Parser/Scan.cpp

@@ -163,7 +163,7 @@ Scanner<EncodingPolicy>::Scanner(Parser* parser, HashTbl *phtbl, Token *ptoken,
     m_fYieldIsKeyword = false;
     m_fAwaitIsKeyword = false;
 
-    m_typeHintsOn = true;
+    m_typeAnnotationsOn = Js::Configuration::Global.flags.TypeAnnotations;
 }
 
 template <typename EncodingPolicy>
@@ -2390,7 +2390,7 @@ LMultiLineComment:
                 commentStartLine = m_line;
                 bool containTypeDef;
                 //FCASTE: Add parsing of @type here
-                token = m_typeHintsOn ? ScanAnnotations(&pchT) : SkipComment(&pchT, &containTypeDef);
+                token = m_typeAnnotationsOn ? ScanAnnotations(&pchT) : SkipComment(&pchT, &containTypeDef);
                 if (token == tkNone) {
                     // Subtract the comment length from the total char count for the purpose
                     // of deciding whether to defer AST and byte code generation.

+ 1 - 1
lib/Parser/Scan.h

@@ -691,7 +691,7 @@ private:
     bool es6UnicodeMode;                // True if ES6Unicode Extensions are enabled.
     bool m_fYieldIsKeyword;             // Whether to treat 'yield' as an identifier or keyword
     bool m_fAwaitIsKeyword;             // Whether to treat 'await' as an identifier or keyword
-    bool m_typeHintsOn;					// True if Type Hint annotations are enabled.
+    bool m_typeAnnotationsOn;           // True if Type Hint annotations are enabled.
 
     // Temporary buffer.
     TemporaryBuffer m_tempChBuf;