nadesiko3 3.7.2 → 3.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/batch/command.txt +472 -469
  2. package/batch/pickup_command.nako3 +1 -1
  3. package/core/.eslintrc.cjs +10 -3
  4. package/core/package-lock.json +1184 -645
  5. package/core/package.json +4 -5
  6. package/core/src/nako3.mjs +8 -6
  7. package/core/src/nako3.mts +19 -16
  8. package/core/src/nako_ast.mts +2 -3
  9. package/core/src/nako_core_version.mjs +2 -2
  10. package/core/src/nako_core_version.mts +2 -2
  11. package/core/src/nako_csv.mjs +1 -0
  12. package/core/src/nako_csv.mts +3 -2
  13. package/core/src/nako_from_dncl.mjs +1 -1
  14. package/core/src/nako_from_dncl.mts +1 -1
  15. package/core/src/nako_from_dncl2.mjs +1 -1
  16. package/core/src/nako_from_dncl2.mts +2 -2
  17. package/core/src/nako_gen.mjs +37 -35
  18. package/core/src/nako_gen.mts +70 -67
  19. package/core/src/nako_global.mjs +3 -2
  20. package/core/src/nako_global.mts +3 -2
  21. package/core/src/nako_lexer.mjs +3 -3
  22. package/core/src/nako_lexer.mts +3 -3
  23. package/core/src/nako_logger.mjs +1 -1
  24. package/core/src/nako_logger.mts +2 -2
  25. package/core/src/nako_parser3.mjs +67 -59
  26. package/core/src/nako_parser3.mts +96 -90
  27. package/core/src/nako_parser_base.mts +3 -3
  28. package/core/src/nako_prepare.mjs +1 -1
  29. package/core/src/nako_prepare.mts +1 -1
  30. package/core/src/nako_source_mapping.mts +0 -1
  31. package/core/src/nako_token.mts +8 -8
  32. package/core/src/nako_types.mts +1 -1
  33. package/core/src/plugin_api.mts +1 -1
  34. package/core/src/plugin_csv.mjs +1 -0
  35. package/core/src/plugin_csv.mts +2 -1
  36. package/core/src/plugin_math.mjs +2 -2
  37. package/core/src/plugin_math.mts +3 -3
  38. package/core/src/plugin_promise.mjs +1 -1
  39. package/core/src/plugin_promise.mts +1 -1
  40. package/core/src/plugin_system.mjs +117 -40
  41. package/core/src/plugin_system.mts +132 -58
  42. package/core/src/plugin_test.mjs +3 -1
  43. package/core/src/plugin_test.mts +3 -1
  44. package/core/test/basic_test.mjs +16 -0
  45. package/core/test/calc_test.mjs +7 -0
  46. package/core/test/plugin_system_test.mjs +33 -0
  47. package/doc/files.md +4 -4
  48. package/doc/plugins.md +1 -1
  49. package/package.json +9 -9
  50. package/release/_hash.txt +36 -121
  51. package/release/_script-tags.txt +16 -33
  52. package/release/command.json +1 -1
  53. package/release/command.json.js +1 -1
  54. package/release/command_cnako3.json +1 -1
  55. package/release/command_list.json +1 -1
  56. package/release/edit_main.js +3 -3
  57. package/release/edit_main.js.map +2 -2
  58. package/release/editor.js +3 -3
  59. package/release/plugin_markup.js +53 -53
  60. package/release/plugin_markup.js.map +3 -3
  61. package/release/plugin_weykturtle3d.js +1 -1
  62. package/release/plugin_weykturtle3d.js.map +4 -4
  63. package/release/version.js +3 -3
  64. package/release/version_main.js +3 -3
  65. package/release/version_main.js.map +2 -2
  66. package/release/wnako3.js +66 -66
  67. package/release/wnako3.js.map +3 -3
  68. package/release/wnako3webworker.js +58 -58
  69. package/release/wnako3webworker.js.map +3 -3
  70. package/src/browsers.txt +30 -20
  71. package/src/cnako3mod.mjs +19 -18
  72. package/src/cnako3mod.mts +17 -16
  73. package/src/deno_wrapper.mjs +6 -6
  74. package/src/deno_wrapper.mts +11 -11
  75. package/src/nako_version.mjs +2 -2
  76. package/src/nako_version.mts +2 -2
  77. package/src/plugin_browser.mjs +2 -2
  78. package/src/plugin_browser.mts +5 -5
  79. package/src/plugin_browser_ajax.mjs +2 -2
  80. package/src/plugin_browser_ajax.mts +2 -2
  81. package/src/plugin_browser_api.mts +0 -1
  82. package/src/plugin_browser_crypto.mjs +8 -8
  83. package/src/plugin_browser_crypto.mts +13 -13
  84. package/src/plugin_browser_dom_basic.mjs +3 -3
  85. package/src/plugin_browser_dom_basic.mts +5 -7
  86. package/src/plugin_browser_dom_event.mjs +1 -1
  87. package/src/plugin_browser_dom_event.mts +2 -1
  88. package/src/plugin_browser_dom_parts.mjs +33 -18
  89. package/src/plugin_browser_dom_parts.mts +60 -59
  90. package/src/plugin_browser_speech.mjs +1 -1
  91. package/src/plugin_browser_speech.mts +1 -1
  92. package/src/plugin_node.mjs +5 -3
  93. package/src/plugin_node.mts +6 -4
  94. package/src/plugin_weykturtle3d.mjs +38 -15
  95. package/src/plugin_weykturtle3d.mts +279 -240
  96. package/src/plugin_weykturtle3d_three.mjs +3 -0
  97. package/src/plugin_weykturtle3d_three.mts +214 -0
  98. package/src/plugin_weykturtle3d_threeutil.mjs +28 -0
  99. package/src/plugin_weykturtle3d_threeutil.mts +31 -0
  100. package/src/wnako3.mjs +1 -0
  101. package/src/wnako3.mts +1 -0
  102. package/src/wnako3mod.mjs +5 -2
  103. package/src/wnako3mod.mts +6 -3
  104. package/batch/command_nakopad.txt +0 -1177
  105. package/core/__report.txt +0 -617
  106. package/core/command/plugin_snako.mjs +0 -112
  107. package/core/command/snako.mjs +0 -108
  108. package/release/core_src_nako_josi_list_mjs.js +0 -3
  109. package/release/core_src_nako_josi_list_mjs.js.LICENSE.txt +0 -3
  110. package/release/core_src_nako_josi_list_mjs.js.map +0 -1
  111. package/release/core_src_nako_reserved_words_mjs.js +0 -3
  112. package/release/core_src_nako_reserved_words_mjs.js.LICENSE.txt +0 -3
  113. package/release/core_src_nako_reserved_words_mjs.js.map +0 -1
  114. package/release/editor/edit_main.js +0 -48
  115. package/release/editor/edit_main.js.map +0 -7
  116. package/release/editor/version_main.js +0 -44
  117. package/release/editor/version_main.js.map +0 -7
  118. package/release/editor.js.LICENSE.txt +0 -91
  119. package/release/editor.js.map +0 -1
  120. package/release/nako_gen_async.js +0 -2
  121. package/release/nako_gen_async.js.LICENSE.txt +0 -21
  122. package/release/nako_gen_async.js.map +0 -1
  123. package/release/plugin_caniuse.js.LICENSE.txt +0 -15
  124. package/release/plugin_datetime.js.LICENSE.txt +0 -21
  125. package/release/plugin_kansuji.js.LICENSE.txt +0 -3
  126. package/release/plugin_markup.js.LICENSE.txt +0 -15
  127. package/release/plugin_toml.js +0 -295
  128. package/release/plugin_toml.js.map +0 -7
  129. package/release/plugin_turtle.js.LICENSE.txt +0 -9
  130. package/release/plugin_webworker.js.LICENSE.txt +0 -3
  131. package/release/plugin_weykturtle3d.js.LICENSE.txt +0 -3
  132. package/release/src/plugin_caniuse.js +0 -2
  133. package/release/src/plugin_caniuse.js.map +0 -7
  134. package/release/src/plugin_datetime.js +0 -2
  135. package/release/src/plugin_datetime.js.map +0 -7
  136. package/release/src/plugin_kansuji.js +0 -2
  137. package/release/src/plugin_kansuji.js.map +0 -7
  138. package/release/src/plugin_keigo.js +0 -2
  139. package/release/src/plugin_keigo.js.map +0 -7
  140. package/release/src/plugin_markup.js +0 -64
  141. package/release/src/plugin_markup.js.map +0 -7
  142. package/release/src/plugin_three.js +0 -2
  143. package/release/src/plugin_three.js.map +0 -7
  144. package/release/src/plugin_turtle.js +0 -2
  145. package/release/src/plugin_turtle.js.map +0 -7
  146. package/release/src/plugin_webworker.js +0 -4
  147. package/release/src/plugin_webworker.js.map +0 -7
  148. package/release/src/plugin_weykturtle3d.js +0 -2
  149. package/release/src/plugin_weykturtle3d.js.map +0 -7
  150. package/release/src/wnako3.js +0 -482
  151. package/release/src/wnako3.js.map +0 -7
  152. package/release/src/wnako3webworker.js +0 -428
  153. package/release/src/wnako3webworker.js.map +0 -7
  154. package/release/stats.json +0 -1
  155. package/release/version.js.LICENSE.txt +0 -65
  156. package/release/version.js.map +0 -1
  157. package/release/wnako3.js.LICENSE.txt +0 -341
  158. package/release/wnako3webworker.js.LICENSE.txt +0 -209
  159. package/src/plugin_three.mts +0 -240
package/core/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nadesiko3core",
3
- "version": "3.7.2",
3
+ "version": "3.7.4",
4
4
  "description": "Japanese Programming Language Nadesiko v3 core",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -38,15 +38,14 @@
38
38
  "sample"
39
39
  ],
40
40
  "devDependencies": {
41
- "@types/mocha": "^10.0.1",
42
- "@types/node": "^20.3.1",
41
+ "@types/mocha": "^10.0.10",
42
+ "@types/node": "^20.17.46",
43
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
43
44
  "chai": "^5.0.0",
44
45
  "eslint": "^8.43.0",
45
46
  "eslint-plugin-import": "^2.27.5",
46
47
  "eslint-plugin-node": "^11.1.0",
47
48
  "eslint-plugin-promise": "^6.1.1",
48
- "@typescript-eslint/eslint-plugin": "^5.60.0",
49
- "eslint-config-standard-with-typescript": "^35.0.0",
50
49
  "mocha": "^10.2.0",
51
50
  "typescript": "^5.5.3"
52
51
  },
@@ -135,7 +135,7 @@ export class NakoCompiler {
135
135
  continue;
136
136
  }
137
137
  // 取り込むライブラリ
138
- let filename = tokens[i + 1].value + '';
138
+ let filename = String(tokens[i + 1].value) + '';
139
139
  // 『取り込む』文で「拡張プラグイン:」機構を追加する #139
140
140
  // (ex) !『貯蔵庫:ojyo-sama.nako3』を取り込む → https://n3s.nadesi.com/plain/ojyo-sama.nako3
141
141
  if (filename.startsWith('貯蔵庫:')) {
@@ -257,7 +257,7 @@ export class NakoCompiler {
257
257
  loadNako3(item, tasks);
258
258
  }
259
259
  else {
260
- throw new NakoImportError(`ファイル『${item.value}』を読み込めません。ファイルが存在しないか未対応の拡張子です。`, item.firstToken.file, item.firstToken.line);
260
+ throw new NakoImportError(`ファイル『${String(item.value)}』を読み込めません。ファイルが存在しないか未対応の拡張子です。`, item.firstToken.file, item.firstToken.line);
261
261
  }
262
262
  }
263
263
  if (tasks.length > 0) {
@@ -282,7 +282,7 @@ export class NakoCompiler {
282
282
  }
283
283
  catch (err) {
284
284
  // 同期処理では素直に例外を投げる
285
- this.logger.error('' + err);
285
+ this.logger.error(String(err));
286
286
  throw err;
287
287
  }
288
288
  }
@@ -464,9 +464,9 @@ export class NakoCompiler {
464
464
  const filePath = Object.keys(this.dependencies).find((key) => this.dependencies[key].alias.has(r.value));
465
465
  if (filePath === undefined) {
466
466
  if (!r.firstToken) {
467
- throw new Error(`ファイル『${r.value}』が読み込まれていません。`);
467
+ throw new Error(`ファイル『${String(r.value)}』が読み込まれていません。`);
468
468
  }
469
- throw new NakoLexerError(`ファイル『${r.value}』が読み込まれていません。`, r.firstToken.startOffset || 0, r.firstToken.endOffset || 0, r.firstToken.line, r.firstToken.file);
469
+ throw new NakoLexerError(`ファイル『${String(r.value)}』が読み込まれていません。`, (r.firstToken).startOffset || 0, (r.firstToken).endOffset || 0, (r.firstToken).line, (r.firstToken).file);
470
470
  }
471
471
  this.dependencies[filePath].addPluginFile();
472
472
  const children = cloneAsJSON(this.dependencies[filePath].tokens);
@@ -669,6 +669,7 @@ export class NakoCompiler {
669
669
  * @param [preCode]
670
670
  * @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
671
671
  */
672
+ // eslint-disable-next-line @typescript-eslint/require-await
672
673
  async _run(code, fname, isReset, isTest, preCode = '') {
673
674
  const opts = newCompilerOptions({
674
675
  resetEnv: isReset,
@@ -702,7 +703,7 @@ export class NakoCompiler {
702
703
  // 実行前に環境を初期化するイベントを実行(beforeRun)
703
704
  this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal));
704
705
  try {
705
- // eslint-disable-next-line no-new-func
706
+ // eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
706
707
  const f = new Function(nakoGlobal.lastJSCode);
707
708
  f.apply(nakoGlobal);
708
709
  }
@@ -740,6 +741,7 @@ export class NakoCompiler {
740
741
  * @param options オプション
741
742
  * @returns 実行に利用したグローバルオブジェクト
742
743
  */
744
+ // eslint-disable-next-line @typescript-eslint/require-await
743
745
  async runAsync(code, filename, options = undefined) {
744
746
  // コンパイル
745
747
  options = newCompilerOptions(options);
@@ -1,3 +1,5 @@
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
1
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
4
  // deno-lint-ignore-file no-explicit-any
3
5
  /**
@@ -9,7 +11,7 @@ import { Ast, AstBlocks } from './nako_ast.mjs'
9
11
  // parser / lexer
10
12
  import { NakoParser } from './nako_parser3.mjs'
11
13
  import { NakoLexer } from './nako_lexer.mjs'
12
- import { NakoPrepare, ConvertResult } from './nako_prepare.mjs'
14
+ import { NakoPrepare } from './nako_prepare.mjs'
13
15
  import { NakoGen, generateJS, NakoGenOptions, NakoGenResult } from './nako_gen.mjs'
14
16
  import { convertInlineIndent, convertIndentSyntax } from './nako_indent_inline.mjs'
15
17
  import { convertDNCL } from './nako_from_dncl.mjs'
@@ -67,14 +69,14 @@ export interface NakoResetOption {
67
69
  }
68
70
 
69
71
  /** コンパイラ実行オプションを生成 */
70
- export function newCompilerOptions (initObj: any = {}): CompilerOptions {
72
+ export function newCompilerOptions (initObj: Partial<CompilerOptions> = {}): CompilerOptions {
71
73
  if (typeof initObj !== 'object') { initObj = {} }
72
74
  initObj.testOnly = initObj.testOnly || false
73
75
  initObj.resetEnv = initObj.resetEnv || false
74
76
  initObj.resetAll = initObj.resetAll || false
75
77
  initObj.preCode = initObj.preCode || ''
76
78
  initObj.nakoGlobal = initObj.nakoGlobal || null
77
- return initObj
79
+ return initObj as CompilerOptions
78
80
  }
79
81
 
80
82
  /** なでしこコンパイラ */
@@ -222,7 +224,7 @@ export class NakoCompiler {
222
224
  continue
223
225
  }
224
226
  // 取り込むライブラリ
225
- let filename = tokens[i + 1].value + ''
227
+ let filename = String(tokens[i + 1].value) + ''
226
228
  // 『取り込む』文で「拡張プラグイン:」機構を追加する #139
227
229
  // (ex) !『貯蔵庫:ojyo-sama.nako3』を取り込む → https://n3s.nadesi.com/plain/ojyo-sama.nako3
228
230
  if (filename.startsWith('貯蔵庫:')) {
@@ -342,7 +344,7 @@ export class NakoCompiler {
342
344
  } else if (item.type === 'nako3') {
343
345
  loadNako3(item, tasks)
344
346
  } else {
345
- throw new NakoImportError(`ファイル『${item.value}』を読み込めません。ファイルが存在しないか未対応の拡張子です。`,
347
+ throw new NakoImportError(`ファイル『${String(item.value)}』を読み込めません。ファイルが存在しないか未対応の拡張子です。`,
346
348
  (item.firstToken as Token).file, (item.firstToken as Token).line)
347
349
  }
348
350
  }
@@ -370,7 +372,7 @@ export class NakoCompiler {
370
372
  return result
371
373
  } catch (err) {
372
374
  // 同期処理では素直に例外を投げる
373
- this.logger.error('' + err)
375
+ this.logger.error(String(err))
374
376
  throw err
375
377
  }
376
378
  }
@@ -562,11 +564,11 @@ export class NakoCompiler {
562
564
  }
563
565
  const filePath = Object.keys(this.dependencies).find((key) => this.dependencies[key].alias.has(r.value))
564
566
  if (filePath === undefined) {
565
- if (!r.firstToken) { throw new Error(`ファイル『${r.value}』が読み込まれていません。`) }
566
- throw new NakoLexerError(`ファイル『${r.value}』が読み込まれていません。`,
567
- (r.firstToken as Token).startOffset || 0,
568
- (r.firstToken as Token).endOffset || 0,
569
- (r.firstToken as Token).line, (r.firstToken as Token).file)
567
+ if (!r.firstToken) { throw new Error(`ファイル『${String(r.value)}』が読み込まれていません。`) }
568
+ throw new NakoLexerError(`ファイル『${String(r.value)}』が読み込まれていません。`,
569
+ (r.firstToken).startOffset || 0,
570
+ (r.firstToken).endOffset || 0,
571
+ (r.firstToken).line, (r.firstToken).file)
570
572
  }
571
573
  this.dependencies[filePath].addPluginFile()
572
574
  const children = cloneAsJSON(this.dependencies[filePath].tokens)
@@ -681,10 +683,9 @@ export class NakoCompiler {
681
683
 
682
684
  _getUsedFuncs (ast: Ast): void {
683
685
  if (!ast) { return }
684
- if ((ast.type === 'func' || ast.type === 'func_pointer')&& ast.name) {
686
+ if ((ast.type === 'func' || ast.type === 'func_pointer') && ast.name) {
685
687
  this.usedFuncs.add(ast.name as string)
686
- }
687
- else if ((ast as AstBlocks).blocks) { // プロパティにblocksを含んでいる?
688
+ } else if ((ast as AstBlocks).blocks) { // プロパティにblocksを含んでいる?
688
689
  for (const a of (ast as AstBlocks).blocks) {
689
690
  this._getUsedFuncs(a)
690
691
  }
@@ -745,7 +746,7 @@ export class NakoCompiler {
745
746
  * @param opt テストかどうか
746
747
  * @param mode 一般的に 'sync' を指定
747
748
  */
748
- generateCode (ast: Ast, opt: NakoGenOptions, mode: string = 'sync'): NakoGenResult {
749
+ generateCode (ast: Ast, opt: NakoGenOptions, mode = 'sync'): NakoGenResult {
749
750
  // Select Code Generator #637
750
751
  // normal mode
751
752
  if (mode === 'sync') {
@@ -776,6 +777,7 @@ export class NakoCompiler {
776
777
  * @param [preCode]
777
778
  * @deprecated 代わりにrunAsyncメソッドを使ってください。(core #52)
778
779
  */
780
+ // eslint-disable-next-line @typescript-eslint/require-await
779
781
  async _run (code: string, fname: string, isReset: boolean, isTest: boolean, preCode = ''): Promise<NakoGlobal> {
780
782
  const opts: CompilerOptions = newCompilerOptions({
781
783
  resetEnv: isReset,
@@ -809,7 +811,7 @@ export class NakoCompiler {
809
811
  // 実行前に環境を初期化するイベントを実行(beforeRun)
810
812
  this.eventList.filter(o => o.eventName === 'beforeRun').map(e => e.callback(nakoGlobal))
811
813
  try {
812
- // eslint-disable-next-line no-new-func
814
+ // eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
813
815
  const f = new Function(nakoGlobal.lastJSCode)
814
816
  f.apply(nakoGlobal)
815
817
  } catch (err: any) {
@@ -848,6 +850,7 @@ export class NakoCompiler {
848
850
  * @param options オプション
849
851
  * @returns 実行に利用したグローバルオブジェクト
850
852
  */
853
+ // eslint-disable-next-line @typescript-eslint/require-await
851
854
  public async runAsync (code: string, filename: string, options: CompilerOptions|undefined = undefined): Promise<NakoGlobal> {
852
855
  // コンパイル
853
856
  options = newCompilerOptions(options)
@@ -57,7 +57,6 @@ export type NodeType = 'nop'
57
57
  | 'speed_mode'
58
58
  | 'run_mode'
59
59
 
60
-
61
60
  /** 基本的なASTの構造 */
62
61
  export interface Ast {
63
62
  type: NodeType;
@@ -156,8 +155,8 @@ export interface AstFor extends AstBlocks {
156
155
  // blocks[1] ... valueTo
157
156
  // blocks[2] ... valueInc
158
157
  // blocks[3] ... loop block
159
- flagDown: boolean; //
160
- flagUp: boolean; //
158
+ flagDown: boolean; //
159
+ flagUp: boolean; //
161
160
  loopDirection: null | 'up' | 'down'; // ループの方向
162
161
  }
163
162
 
@@ -1,8 +1,8 @@
1
1
  // 実際のバージョン定義 (自動生成されるので以下を編集しない)
2
2
  const coreVersion = {
3
- version: '3.7.2',
3
+ version: '3.7.4',
4
4
  major: 3,
5
5
  minor: 7,
6
- patch: 2
6
+ patch: 4
7
7
  };
8
8
  export default coreVersion;
@@ -11,9 +11,9 @@ export interface NakoCoreVersion {
11
11
  }
12
12
  // 実際のバージョン定義 (自動生成されるので以下を編集しない)
13
13
  const coreVersion: NakoCoreVersion = {
14
- version: '3.7.2',
14
+ version: '3.7.4',
15
15
  major: 3,
16
16
  minor: 7,
17
- patch: 2
17
+ patch: 4
18
18
  }
19
19
  export default coreVersion
@@ -9,6 +9,7 @@ export function resetEnv() {
9
9
  options.auto_convert_number = true;
10
10
  }
11
11
  /// 文字列が数値化どうか判定する関数
12
+ // eslint-disable-next-line camelcase
12
13
  function is_numeric(str) {
13
14
  return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(str);
14
15
  }
@@ -18,8 +18,9 @@ export function resetEnv (): void {
18
18
  }
19
19
 
20
20
  /// 文字列が数値化どうか判定する関数
21
- function is_numeric(str: string): boolean {
22
- return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(str);
21
+ // eslint-disable-next-line camelcase
22
+ function is_numeric (str: string): boolean {
23
+ return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(str)
23
24
  }
24
25
 
25
26
  export function parse (txt: string, delimiter: string|undefined = undefined): (string|number)[][] {
@@ -201,7 +201,7 @@ export function convertDNCL(tokens) {
201
201
  // 最後に単純な置換を行う
202
202
  for (let i = 0; i < tokens.length; i++) {
203
203
  const t = tokens[i];
204
- const a = DNCL_SIMPLES[t.type + ':' + t.value];
204
+ const a = DNCL_SIMPLES[String(t.type) + ':' + String(t.value)];
205
205
  if (a !== undefined) {
206
206
  t.type = a[0];
207
207
  t.value = a[1];
@@ -182,7 +182,7 @@ export function convertDNCL (tokens: Token[]): Token[] {
182
182
  // 最後に単純な置換を行う
183
183
  for (let i = 0; i < tokens.length; i++) {
184
184
  const t = tokens[i]
185
- const a = DNCL_SIMPLES[t.type + ':' + t.value]
185
+ const a = DNCL_SIMPLES[String(t.type) + ':' + String(t.value)]
186
186
  if (a !== undefined) {
187
187
  t.type = a[0] as TokenType
188
188
  t.value = a[1]
@@ -247,7 +247,7 @@ export function convertDNCL2(tokens) {
247
247
  // 最後に単純な置換を行う
248
248
  for (let i = 0; i < tokens.length; i++) {
249
249
  const t = tokens[i];
250
- const a = DNCL_SIMPLES[t.type + ':' + t.value];
250
+ const a = DNCL_SIMPLES[String(t.type) + ':' + String(t.value)];
251
251
  if (a !== undefined) {
252
252
  t.type = a[0];
253
253
  t.value = a[1];
@@ -250,7 +250,7 @@ export function convertDNCL2 (tokens: Token[]): Token[] {
250
250
  // 最後に単純な置換を行う
251
251
  for (let i = 0; i < tokens.length; i++) {
252
252
  const t = tokens[i]
253
- const a = DNCL_SIMPLES[t.type + ':' + t.value]
253
+ const a = DNCL_SIMPLES[String(t.type) + ':' + String(t.value)]
254
254
  if (a !== undefined) {
255
255
  t.type = a[0] as TokenType
256
256
  t.value = a[1]
@@ -273,7 +273,7 @@ export function convertDNCL2 (tokens: Token[]): Token[] {
273
273
  * @returns 合致したかどうか
274
274
  */
275
275
  function tokenEq (typeValues: any[], lines: Token[], fromIndex: number): boolean {
276
- const check = (pattern: string|Array<string>, t: Token): boolean => {
276
+ const check = (pattern: string|Array<string>, t: { type: string, value: string }): boolean => {
277
277
  if (pattern instanceof Array) {
278
278
  for (let i = 0; i < pattern.length; i++) {
279
279
  if (check(pattern[i], t)) { return true }
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
1
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
3
  /**
3
4
  * パーサーが生成した中間オブジェクトを実際のJavaScriptのコードに変換する。
@@ -224,6 +225,7 @@ export class NakoGen {
224
225
  }
225
226
  /** @param {Ast} node */
226
227
  static convPrint(node) {
228
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
227
229
  return `__print(${node});`;
228
230
  }
229
231
  /** @param {AstStrValue} node */
@@ -254,7 +256,7 @@ export class NakoGen {
254
256
  code += 'const __line = (lineno) => { __self.__v0.set(\'__line\', lineno); }\n';
255
257
  code += '__v0.set(\'__line\', \'l0:__getDefFuncCode\');\n';
256
258
  code += '__v0.set(\'__forceClose\', false);\n';
257
- code += `__v0.set('__useDebug', ${this.debugOption.useDebug});\n`;
259
+ code += `__v0.set('__useDebug', ${String(this.debugOption.useDebug)});\n`;
258
260
  // 定数を埋め込む
259
261
  code += '__self.constPools = ' + JSON.stringify(this.constPools) + ';\n';
260
262
  code += '__self.constPoolsTemplate = ' + JSON.stringify(this.constPoolsTemplate) + ';\n';
@@ -278,7 +280,7 @@ export class NakoGen {
278
280
  let testCode = 'const __tests = [];\n';
279
281
  this.nakoTestFuncs.forEach((value) => {
280
282
  const f = value.fn;
281
- testCode += `${f};\n`;
283
+ testCode += `${String(f)};\n`;
282
284
  });
283
285
  if (testCode !== '') {
284
286
  code += '__v0.set(\'__line\', \'テストの定義\');\n';
@@ -357,7 +359,7 @@ export class NakoGen {
357
359
  // eslint-disable-next-line @typescript-eslint/no-empty-function
358
360
  fn: () => { },
359
361
  type: 'func',
360
- asyncFn: t.asyncFn ? true : false,
362
+ asyncFn: !!t.asyncFn,
361
363
  isExport: t.isExport
362
364
  });
363
365
  funcList.push({ name, node: t });
@@ -367,7 +369,7 @@ export class NakoGen {
367
369
  if (ast.blocks) {
368
370
  // 各ブロックをくまなく巡回チェック
369
371
  for (const t of ast.blocks) {
370
- if (t.type == 'def_func') { // 関数定義
372
+ if (t.type === 'def_func') { // 関数定義
371
373
  registFunc(t);
372
374
  }
373
375
  else {
@@ -423,7 +425,7 @@ export class NakoGen {
423
425
  return 'undefined';
424
426
  }
425
427
  if (typeof (node) !== 'object') {
426
- return '' + node;
428
+ return '' + String(node);
427
429
  }
428
430
  // switch
429
431
  switch (node.type) {
@@ -584,7 +586,7 @@ export class NakoGen {
584
586
  name,
585
587
  isTop: false,
586
588
  js: `__self.__varslist[${i}].get(${JSON.stringify(name)})`,
587
- js_set: `__self.__varslist[${i}].set(${JSON.stringify(name)}, ${jsvalue})`
589
+ js_set: `__self.__varslist[${i}].set(${JSON.stringify(name)}, ${jsvalue ?? 'undefined'})`
588
590
  };
589
591
  }
590
592
  }
@@ -621,7 +623,7 @@ export class NakoGen {
621
623
  if (i === 0) {
622
624
  const pv = this.__self.getNakoFunc(name);
623
625
  if (!pv) {
624
- return `${res.js}/*[link_error]l${lno}:${position.file}*/`;
626
+ return `${res.js}/*[link_error]l${lno}:${position.file ?? 'unknown'}*/`;
625
627
  }
626
628
  if (pv.type === 'const' || pv.type === 'var') {
627
629
  return res.js;
@@ -714,15 +716,15 @@ export class NakoGen {
714
716
  }
715
717
  addConstPool(msg, args, file, line) {
716
718
  // file
717
- file = '' + file;
719
+ file = String(file);
718
720
  const fileNo = this.getConstPoolsTemplateId(file);
719
721
  // msg
720
722
  const msgNo = this.getConstPoolsTemplateId(msg);
721
723
  // args
722
724
  const args2 = [];
723
- for (const i in args) {
724
- const arg = '' + args[i];
725
- const argNo = this.getConstPoolsTemplateId(arg);
725
+ for (const arg of args) {
726
+ const argStr = '' + String(arg);
727
+ const argNo = this.getConstPoolsTemplateId(argStr);
726
728
  args2.push(argNo);
727
729
  }
728
730
  const poolIndex = this.constPools.length;
@@ -1103,7 +1105,7 @@ export class NakoGen {
1103
1105
  `const ${varFrom} = ${kara};\n` +
1104
1106
  `const ${varTo} = ${made};\n` +
1105
1107
  `if (${varFrom} <= ${varTo}) { // up\n` +
1106
- ` if (${flagUp}) {` +
1108
+ ` if (${String(flagUp)}) {` +
1107
1109
  ` for (let ${varI} = ${varFrom}; ${varI} <= ${varTo}; ${varI}+= ${inc}) {\n` +
1108
1110
  ` ${sorePrefex};${loopVarSetter}\n` +
1109
1111
  ' // for block begin\n' +
@@ -1112,7 +1114,7 @@ export class NakoGen {
1112
1114
  ' };\n' +
1113
1115
  ' };\n' +
1114
1116
  '} else { // down\n' +
1115
- ` if (${flagDown}) {` +
1117
+ ` if (${String(flagDown)}) {` +
1116
1118
  ` for (let ${varI} = ${varFrom}; ${varI} >= ${varTo}; ${varI}-= ${inc}) {\n` +
1117
1119
  ` ${sorePrefex};${loopVarSetter}\n` +
1118
1120
  ' // for block begin\n' +
@@ -1362,11 +1364,11 @@ export class NakoGen {
1362
1364
  }
1363
1365
  else {
1364
1366
  let argCode = this._convGen(arg, true);
1365
- if (argCode === "") {
1367
+ if (argCode === '') {
1366
1368
  argCode = 'undefined';
1367
1369
  }
1368
1370
  if (typeof argCode !== 'string') {
1369
- argCode = "undefined";
1371
+ argCode = 'undefined';
1370
1372
  }
1371
1373
  args.push(`/*arg${i}*/${argCode}`);
1372
1374
  }
@@ -1407,7 +1409,7 @@ export class NakoGen {
1407
1409
  func = this.nakoFuncList.get(funcName);
1408
1410
  // 無名関数の可能性
1409
1411
  if (func === undefined) {
1410
- func = { return_none: false, asyncFn: node.asyncFn ? true : false };
1412
+ func = { return_none: false, asyncFn: !!node.asyncFn };
1411
1413
  }
1412
1414
  }
1413
1415
  // 関数の参照渡しか?
@@ -1652,7 +1654,7 @@ export class NakoGen {
1652
1654
  let right = this._convGen(node.blocks[1], true);
1653
1655
  let left = this._convGen(node.blocks[0], true);
1654
1656
  if (op === '+' && this.speedMode.implicitTypeCasting === 0) {
1655
- if (node.blocks[0] && (node.blocks[0]).type !== 'number' && node.blocks[0].type !== 'bigint') {
1657
+ if (node.blocks[0] && (node.blocks[0]).type !== 'number' && (node.blocks[0]).type !== 'bigint') {
1656
1658
  left = `self.__parseFloatOrBigint(${left})`;
1657
1659
  }
1658
1660
  if (node.blocks[1] && (node.blocks[1]).type !== 'number' && (node.blocks[1]).type !== 'bigint') {
@@ -1768,10 +1770,10 @@ export class NakoGen {
1768
1770
  }
1769
1771
  // プロパティへの代入式 (#1793)
1770
1772
  convLetProp(node) {
1771
- if (!node.index || node.index.length == 0) {
1773
+ if (!node.index || node.index.length === 0) {
1772
1774
  throw NakoSyntaxError.fromNode('代入する先のプロパティ名がありません。', node);
1773
1775
  }
1774
- if (!node.blocks || node.blocks.length == 0) {
1776
+ if (!node.blocks || node.blocks.length === 0) {
1775
1777
  throw NakoSyntaxError.fromNode('代入する値がありません。', node);
1776
1778
  }
1777
1779
  const propList = node.index;
@@ -1827,13 +1829,13 @@ export class NakoGen {
1827
1829
  const propList = list;
1828
1830
  if (propList.length <= 1) {
1829
1831
  const propKey = propList[0].value;
1830
- const code_call = `${name}.__getProp('${propKey}', __self)`;
1831
- const code_prop = `${name}['${propKey}']`;
1832
- const code_checkAccessor = `__self.__checkPropAccessor('get', ${name});\n` +
1833
- `if (typeof ${name}.__getProp === 'function') { return ${code_call} }\n` +
1834
- `return ${code_prop}\n`;
1835
- const code_if = `if (${name}.__getProp) { return ${code_call} } else { ${code_checkAccessor} }`;
1836
- code = `( (()=>{ ${code_if} })() )`;
1832
+ const codeCall = `${name}.__getProp('${propKey}', __self)`;
1833
+ const codeProp = `${name}['${propKey}']`;
1834
+ const codeCheckAccessor = `__self.__checkPropAccessor('get', ${name});\n` +
1835
+ `if (typeof ${name}.__getProp === 'function') { return ${codeCall} }\n` +
1836
+ `return ${codeProp}\n`;
1837
+ const codeIf = `if (${name}.__getProp) { return ${codeCall} } else { ${codeCheckAccessor} }`;
1838
+ code = `( (()=>{ ${codeIf} })() )`;
1837
1839
  }
1838
1840
  else {
1839
1841
  const arrs = [];
@@ -1845,13 +1847,13 @@ export class NakoGen {
1845
1847
  }
1846
1848
  const keyStr = keys.join('');
1847
1849
  const arrStr = '[' + arrs.join(',') + ']';
1848
- const code_call = `${name}.__getProp(${arrStr}, __self)`;
1849
- const code_prop = `${name}${keyStr}`;
1850
- const code_checkAccessor = `__self.__checkPropAccessor('get', ${name});\n` +
1851
- `if (${name}.__getProp) { return ${code_call} }\n` +
1852
- `return ${code_prop}\n`;
1853
- const code_if = `if (${name}.__getProp) { return ${code_call} } else { ${code_checkAccessor} }`;
1854
- code = `( (()=>{ ${code_if} })() )`;
1850
+ const codeCall = `${name}.__getProp(${arrStr}, __self)`;
1851
+ const codeProp = `${name}${keyStr}`;
1852
+ const codeCheckAccessor = `__self.__checkPropAccessor('get', ${name});\n` +
1853
+ `if (${name}.__getProp) { return ${codeCall} }\n` +
1854
+ `return ${codeProp}\n`;
1855
+ const codeIf = `if (${name}.__getProp) { return ${codeCall} } else { ${codeCheckAccessor} }`;
1856
+ code = `( (()=>{ ${codeIf} })() )`;
1855
1857
  }
1856
1858
  return code;
1857
1859
  }
@@ -1913,7 +1915,7 @@ export class NakoGen {
1913
1915
  '/*[/convDefLocalVarlist]*/\n';
1914
1916
  }
1915
1917
  convString(node) {
1916
- let value = '' + node.value;
1918
+ let value = String(node.value);
1917
1919
  value = value.replace(/\\/g, '\\\\');
1918
1920
  value = value.replace(/"/g, '\\"');
1919
1921
  value = value.replace(/\r/g, '\\r');
@@ -2055,7 +2057,7 @@ export function generateJS(com, ast, opt) {
2055
2057
  // (3) JSコードを実行するための事前ヘッダ部分の生成
2056
2058
  const jsInit = gen.getDefFuncCode(com, opt);
2057
2059
  // ランダムな関数名を生成
2058
- const funcID = '' + (new Date()).getTime() + '_' + Math.floor(0xFFFFFFFF * Math.random());
2060
+ const funcID = String((new Date()).getTime()) + '_' + Math.floor(0xFFFFFFFF * Math.random()).toString();
2059
2061
  // テストの実行
2060
2062
  if (js && opt.isTest) {
2061
2063
  js += '\n__self._runTests(__tests);\n';