@@ -1619,7 +1619,12 @@ void MetadataNode::CreateTopLevelNamespaces(Isolate* isolate, const Local<Object
16191619 auto node = GetOrCreateInternal (treeNode);
16201620
16211621 auto packageObj = node->CreateWrapper (isolate);
1622- global->Set (ArgConverter::ConvertToV8String (isolate, node->m_treeNode ->name ), packageObj);
1622+ string nameSpace = node->m_treeNode ->name ;
1623+ // if the namespaces matches a javascript keyword, prefix it with $ to avoid TypeScript and JavaScript errors
1624+ if (IsJavascriptKeyword (nameSpace)) {
1625+ nameSpace = " $" + nameSpace;
1626+ }
1627+ global->Set (ArgConverter::ConvertToV8String (isolate, nameSpace), packageObj);
16231628 }
16241629 }
16251630}
@@ -1640,25 +1645,29 @@ void MetadataNode::EnableProfiler(bool enableProfiler) {
16401645 s_profilerEnabled = enableProfiler;
16411646}
16421647
1643- Local<Function> MetadataNode::Wrap (Isolate* isolate, const Local<Function>& function, const string& name, const string& origin, bool isCtorFunc) {
1644- if (!s_profilerEnabled || name == " <init>" ) {
1645- return function;
1646- }
1647-
1648+ bool MetadataNode::IsJavascriptKeyword (std::string word) {
16481649 static set<string> keywords;
16491650
16501651 if (keywords.empty ()) {
16511652 string kw[] { " abstract" , " arguments" , " boolean" , " break" , " byte" , " case" , " catch" , " char" , " class" , " const" , " continue" , " debugger" , " default" , " delete" , " do" ,
16521653 " double" , " else" , " enum" , " eval" , " export" , " extends" , " false" , " final" , " finally" , " float" , " for" , " function" , " goto" , " if" , " implements" ,
16531654 " import" , " in" , " instanceof" , " int" , " interface" , " let" , " long" , " native" , " new" , " null" , " package" , " private" , " protected" , " public" , " return" ,
16541655 " short" , " static" , " super" , " switch" , " synchronized" , " this" , " throw" , " throws" , " transient" , " true" , " try" , " typeof" , " var" , " void" , " volatile" , " while" , " with" , " yield"
1655- };
1656+ };
16561657
16571658 keywords = set<string>(kw, kw + sizeof (kw)/sizeof (kw[0 ]));
16581659 }
16591660
1661+ return keywords.find (word) != keywords.end ();
1662+ }
1663+
1664+ Local<Function> MetadataNode::Wrap (Isolate* isolate, const Local<Function>& function, const string& name, const string& origin, bool isCtorFunc) {
1665+ if (!s_profilerEnabled || name == " <init>" ) {
1666+ return function;
1667+ }
1668+
16601669 string actualName = name;
1661- while (keywords. find (actualName) != keywords. end ( )) {
1670+ while (IsJavascriptKeyword (actualName)) {
16621671 actualName.append (" _" );
16631672 }
16641673
0 commit comments