Skip to content

Commit 86299b1

Browse files
committed
build: prefix reserved words with underscores
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b2dd31c commit 86299b1

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

lib/node_modules/@stdlib/_tools/scripts/create_namespace_types.js

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* limitations under the License.
1919
*/
2020

21-
/* eslint-disable node/no-sync, no-console */
21+
/* eslint-disable node/no-sync, no-console, max-statements */
2222

2323
'use strict';
2424

@@ -44,6 +44,54 @@ var RE_TS_EXPORT = /export = ([^;]+);/;
4444
var RE_EXAMPLE = /@example[\s\S]*?(?=@example|\*\/)/g;
4545
var RE_NAMESPACE = /@namespace ([a-z.0-9]+)/i;
4646
var RE_COPYRIGHT_YEAR = /Copyright \(c\) (\d{4}) The Stdlib Authors\./;
47+
var RESERVED_WORDS = [
48+
'break',
49+
'case',
50+
'catch',
51+
'class',
52+
'const',
53+
'continue',
54+
'debugger',
55+
'default',
56+
'delete',
57+
'do',
58+
'else',
59+
'export',
60+
'extends',
61+
'false',
62+
'finally',
63+
'for',
64+
'function',
65+
'if',
66+
'import',
67+
'in',
68+
'instanceof',
69+
'new',
70+
'null',
71+
'return',
72+
'super',
73+
'switch',
74+
'this',
75+
'throw',
76+
'true',
77+
'try',
78+
'typeof',
79+
'var',
80+
'void',
81+
'while',
82+
'with',
83+
'let',
84+
'static',
85+
'yield',
86+
'await',
87+
'enum',
88+
'implements',
89+
'interface',
90+
'package',
91+
'private',
92+
'protected',
93+
'public'
94+
];
4795

4896

4997
// FUNCTIONS //
@@ -175,6 +223,7 @@ function create( fullPath ) {
175223
var tsDefPath;
176224
var testFile;
177225
var typesDir;
226+
var safeName;
178227
var defFile;
179228
var pkgPath;
180229
var match;
@@ -237,11 +286,16 @@ function create( fullPath ) {
237286
}
238287
while ( match !== null ) {
239288
name = match[ 1 ];
289+
if ( contains( RESERVED_WORDS, name ) ) {
290+
safeName = '_' + name;
291+
} else {
292+
safeName = name;
293+
}
240294
pkgPath = match[ 2 ];
241295

242296
tsDefPath = replace( require.resolve( pkgPath ), 'lib/index.js', 'docs/types/index.d.ts' );
243297
if ( fs.existsSync( tsDefPath ) ) {
244-
stmt = replace( IMPORT_STATEMENT, '<name>', name );
298+
stmt = replace( IMPORT_STATEMENT, '<name>', safeName );
245299
stmt = replace( stmt, '<path>', pkgPath );
246300
importStmts.push( stmt );
247301

@@ -253,7 +307,7 @@ function create( fullPath ) {
253307
if ( !tsDoc ) {
254308
tsDoc = tsDef.match( /(\/\*\*\n[^/]+?\*\/)\ndeclare class/ );
255309
}
256-
prop = '\t'+name+': typeof '+name+';';
310+
prop = '\t'+name+': typeof '+safeName+';';
257311
if ( tsDoc && tsDoc[ 1 ] ) {
258312
str = tsDoc[ 1 ];
259313
str = replace( str, RE_EXAMPLE, onReplace );

0 commit comments

Comments
 (0)