nadesiko3 3.2.51 → 3.3.2

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 (169) hide show
  1. package/README.md +1 -1
  2. package/bin/cnako3 +1 -1
  3. package/bin/cnako3.bat +1 -1
  4. package/demo/browsers.html +9 -10
  5. package/demo/flow.html +1 -0
  6. package/demo/turtle3.html +18 -17
  7. package/demo/turtle3d.html +1 -1
  8. package/demo/turtle3d2.html +1 -1
  9. package/doc/browsers.md +9 -10
  10. package/package.json +58 -57
  11. package/release/_hash.txt +57 -52
  12. package/release/_script-tags.txt +14 -13
  13. package/release/command.json +1 -1
  14. package/release/command.json.js +1 -1
  15. package/release/command_cnako3.json +1 -1
  16. package/release/command_list.json +1 -1
  17. package/release/editor.js +1 -1
  18. package/release/editor.js.LICENSE.txt +9 -12
  19. package/release/nako_gen_async.js +1 -1
  20. package/release/nako_gen_async.js.LICENSE.txt +10 -666
  21. package/release/plugin_caniuse.js +1 -1
  22. package/release/plugin_caniuse.js.LICENSE.txt +9 -425
  23. package/release/plugin_csv.js +1 -1
  24. package/release/plugin_csv.js.LICENSE.txt +3 -419
  25. package/release/plugin_datetime.js +1 -1
  26. package/release/plugin_datetime.js.LICENSE.txt +6 -530
  27. package/release/plugin_kansuji.js +1 -1
  28. package/release/plugin_kansuji.js.LICENSE.txt +3 -559
  29. package/release/plugin_markup.js +1 -1
  30. package/release/plugin_markup.js.LICENSE.txt +4 -420
  31. package/release/plugin_turtle.js +1 -1
  32. package/release/plugin_turtle.js.LICENSE.txt +12 -500
  33. package/release/plugin_webworker.js +1 -1
  34. package/release/plugin_webworker.js.LICENSE.txt +3 -563
  35. package/release/plugin_weykturtle3d.js +1 -0
  36. package/release/stats.json +1 -1
  37. package/release/version.js +1 -1
  38. package/release/version.js.LICENSE.txt +9 -12
  39. package/release/wnako3.js +1 -1
  40. package/release/wnako3.js.LICENSE.txt +1 -1
  41. package/release/wnako3webworker.js +1 -1
  42. package/release/wnako3webworker.js.LICENSE.txt +1 -1117
  43. package/src/browsers.mjs +1 -0
  44. package/src/browsers.txt +15 -15
  45. package/src/browsers_agents.mjs +1 -0
  46. package/src/cnako3.mjs +13 -0
  47. package/src/{cnako3.js → cnako3mod.mjs} +46 -53
  48. package/src/{commander_ja.js → commander_ja.mjs} +16 -11
  49. package/src/{enako3.js → enako3.mjs} +0 -0
  50. package/src/{era.json → era.mjs} +1 -1
  51. package/src/image_turtle-elephant.mjs +5 -0
  52. package/src/image_turtle-panda.mjs +5 -0
  53. package/src/image_turtle64.mjs +5 -0
  54. package/src/index.mjs +9 -0
  55. package/src/{nako3.js → nako3.mjs} +56 -52
  56. package/src/{nako3_assert.js → nako3_assert.mjs} +7 -6
  57. package/src/{nako3server.js → nako3server.mjs} +12 -5
  58. package/src/{nako_colors.js → nako_colors.mjs} +1 -1
  59. package/src/{nako_errors.js → nako_errors.mjs} +8 -18
  60. package/src/{nako_from_dncl.js → nako_from_dncl.mjs} +8 -6
  61. package/src/{nako_gen.js → nako_gen.mjs} +107 -89
  62. package/src/{nako_gen_async.js → nako_gen_async.mjs} +5 -8
  63. package/src/{nako_global.js → nako_global.mjs} +4 -5
  64. package/src/{nako_indent.js → nako_indent.mjs} +4 -4
  65. package/src/{nako_josi_list.js → nako_josi_list.mjs} +16 -14
  66. package/src/nako_lex_rules.mjs +244 -0
  67. package/src/{nako_lexer.js → nako_lexer.mjs} +7 -10
  68. package/src/{nako_logger.js → nako_logger.mjs} +3 -4
  69. package/src/{nako_parser3.js → nako_parser3.mjs} +5 -5
  70. package/src/{nako_parser_base.js → nako_parser_base.mjs} +1 -9
  71. package/src/{nako_parser_const.js → nako_parser_const.mjs} +2 -6
  72. package/src/{nako_prepare.js → nako_prepare.mjs} +1 -2
  73. package/src/{nako_reserved_words.js → nako_reserved_words.mjs} +1 -1
  74. package/src/{nako_source_mapping.js → nako_source_mapping.mjs} +4 -11
  75. package/src/{nako_test.js → nako_test.mjs} +0 -0
  76. package/src/nako_version.mjs +7 -0
  77. package/src/{plugin_browser.js → plugin_browser.mjs} +30 -30
  78. package/src/{plugin_browser_ajax.js → plugin_browser_ajax.mjs} +7 -7
  79. package/src/{plugin_browser_audio.js → plugin_browser_audio.mjs} +1 -1
  80. package/src/{plugin_browser_canvas.js → plugin_browser_canvas.mjs} +1 -1
  81. package/src/{plugin_browser_chart.js → plugin_browser_chart.mjs} +1 -1
  82. package/src/{plugin_browser_color.js → plugin_browser_color.mjs} +1 -1
  83. package/src/{plugin_browser_crypto.js → plugin_browser_crypto.mjs} +1 -1
  84. package/src/{plugin_browser_dialog.js → plugin_browser_dialog.mjs} +1 -1
  85. package/src/{plugin_browser_dom_basic.js → plugin_browser_dom_basic.mjs} +1 -1
  86. package/src/{plugin_browser_dom_event.js → plugin_browser_dom_event.mjs} +1 -1
  87. package/src/{plugin_browser_dom_parts.js → plugin_browser_dom_parts.mjs} +1 -1
  88. package/src/{plugin_browser_geolocation.js → plugin_browser_geolocation.mjs} +1 -1
  89. package/src/{plugin_browser_hotkey.js → plugin_browser_hotkey.mjs} +2 -2
  90. package/src/{plugin_browser_html.js → plugin_browser_html.mjs} +1 -1
  91. package/src/{plugin_browser_in_worker.js → plugin_browser_in_worker.mjs} +4 -4
  92. package/src/{plugin_browser_location.js → plugin_browser_location.mjs} +1 -1
  93. package/src/{plugin_browser_speech.js → plugin_browser_speech.mjs} +1 -1
  94. package/src/{plugin_browser_storage.js → plugin_browser_storage.mjs} +1 -1
  95. package/src/{plugin_browser_system.js → plugin_browser_system.mjs} +1 -1
  96. package/src/{plugin_browser_websocket.js → plugin_browser_websocket.mjs} +1 -1
  97. package/src/{plugin_caniuse.js → plugin_caniuse.mjs} +8 -3
  98. package/src/{plugin_csv.js → plugin_csv.mjs} +4 -5
  99. package/src/{plugin_datetime.js → plugin_datetime.mjs} +19 -26
  100. package/src/{plugin_express.js → plugin_express.mjs} +4 -3
  101. package/src/{plugin_kansuji.js → plugin_kansuji.mjs} +1 -1
  102. package/src/{plugin_keigo.js → plugin_keigo.mjs} +0 -0
  103. package/src/{plugin_markup.js → plugin_markup.mjs} +6 -6
  104. package/src/{plugin_math.js → plugin_math.mjs} +1 -4
  105. package/src/{plugin_node.js → plugin_node.mjs} +25 -57
  106. package/src/{plugin_promise.js → plugin_promise.mjs} +1 -3
  107. package/src/{plugin_system.js → plugin_system.mjs} +32 -15
  108. package/src/{plugin_test.js → plugin_test.mjs} +1 -3
  109. package/src/{plugin_turtle.js → plugin_turtle.mjs} +5 -4
  110. package/src/{plugin_webworker.js → plugin_webworker.mjs} +3 -3
  111. package/src/{plugin_weykturtle3d.js → plugin_weykturtle3d.mjs} +1 -3
  112. package/src/{plugin_worker.js → plugin_worker.mjs} +4 -1
  113. package/src/{wnako3.js → wnako3.mjs} +5 -5
  114. package/src/{wnako3_editor.js → wnako3_editor.mjs} +24 -18
  115. package/src/{wnako3webworker.js → wnako3webworker.mjs} +0 -0
  116. package/test/async/{async_basic_test.js → async_basic_test.mjs} +3 -4
  117. package/test/browser/karma.config.js +9 -0
  118. package/test/browser/test/plugin_browser_test.js +2 -2
  119. package/test/browser/test/plugin_turtle_test.js +2 -2
  120. package/test/browser/test/plugin_webworker_test.js +3 -3
  121. package/test/browser/test/require_test.js +2 -2
  122. package/test/common/{array_test.js → array_test.mjs} +3 -3
  123. package/test/common/{basic_test.js → basic_test.mjs} +3 -13
  124. package/test/common/{calc_test.js → calc_test.mjs} +2 -2
  125. package/test/common/{debug_test.js → debug_test.mjs} +2 -2
  126. package/test/common/{dncl_test.js → dncl_test.mjs} +3 -3
  127. package/test/common/{error_test.js → error_test.mjs} +2 -2
  128. package/test/common/{flow_test.js → flow_test.mjs} +2 -2
  129. package/test/common/{func_call.js → func_call.mjs} +3 -3
  130. package/test/common/{func_test.js → func_test.mjs} +2 -2
  131. package/test/common/{indent_test.js → indent_test.mjs} +3 -2
  132. package/test/common/{lex_test.js → lex_test.mjs} +2 -2
  133. package/test/common/{literal_test.js → literal_test.mjs} +3 -2
  134. package/test/common/{nako_logger_test.js → nako_logger_test.mjs} +3 -3
  135. package/test/common/{plugin_browser_test.js → plugin_browser_test.mjs} +4 -4
  136. package/test/common/{plugin_browser_ut_audio_test.js → plugin_browser_ut_audio_test.mjs} +4 -4
  137. package/test/common/{plugin_browser_ut_color_test.js → plugin_browser_ut_color_test.mjs} +2 -2
  138. package/test/common/{plugin_browser_ut_dialog_test.js → plugin_browser_ut_dialog_test.mjs} +3 -3
  139. package/test/common/{plugin_browser_ut_html_test.js → plugin_browser_ut_html_test.mjs} +2 -2
  140. package/test/common/{plugin_browser_ut_system_test.js → plugin_browser_ut_system_test.mjs} +2 -2
  141. package/test/common/{plugin_csv_test.js → plugin_csv_test.mjs} +3 -3
  142. package/test/common/{plugin_datetime_test.js → plugin_datetime_test.mjs} +4 -4
  143. package/test/common/{plugin_kansuji_test.js → plugin_kansuji_test.mjs} +3 -3
  144. package/test/common/{plugin_markup_test.js → plugin_markup_test.mjs} +3 -3
  145. package/test/common/{plugin_promise_test.js → plugin_promise_test.mjs} +2 -2
  146. package/test/common/{plugin_system_test.js → plugin_system_test.mjs} +2 -2
  147. package/test/common/{prepare_test.js → prepare_test.mjs} +2 -2
  148. package/test/common/{re_test.js → re_test.mjs} +2 -2
  149. package/test/common/{variable_scope_test.js → variable_scope_test.mjs} +2 -2
  150. package/test/karma.config.js +3 -3
  151. package/test/node/{async_test.js → async_test.mjs} +4 -2
  152. package/test/node/{commander_ja_test.js → commander_ja_test.mjs} +17 -12
  153. package/test/node/{error_message_test.js → error_message_test.mjs} +13 -10
  154. package/test/node/node_test.mjs +57 -0
  155. package/test/node/{plugin_browser_ut_ajax_test.js → plugin_browser_ut_ajax_test.mjs} +7 -5
  156. package/test/node/{plugin_browser_ut_location_test.js → plugin_browser_ut_location_test.mjs} +3 -3
  157. package/test/node/{plugin_markup_test.js → plugin_markup_test.mjs} +6 -7
  158. package/test/node/{plugin_math_test.js → plugin_math_test.mjs} +5 -5
  159. package/test/node/{plugin_node_test.js → plugin_node_test.mjs} +11 -7
  160. package/test/node/{plugin_test.js → plugin_test.mjs} +11 -5
  161. package/test/node/{require_nako3_test.js → require_nako3_test.mjs} +19 -12
  162. package/test/node/{side_effects_test.js → side_effects_test.mjs} +24 -13
  163. package/test/node/{wnako3_editor_test.js → wnako3_editor_test.mjs} +16 -9
  164. package/tools/nako3edit/index.nako3 +1 -1
  165. package/tools/nako3edit/{run.js → run.mjs} +8 -2
  166. package/src/index.js +0 -5
  167. package/src/nako_lex_rules.js +0 -260
  168. package/src/nako_version.js +0 -8
  169. package/test/node/node_test.js +0 -43
@@ -1,46 +1,30 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * file: plugin_node.js
4
3
  * node.js のためのプラグイン
5
4
  */
6
- const fs = require('fs')
7
- const fse = require('fs-extra')
8
- const fetch = require('node-fetch')
9
- const childProcess = require('child_process')
10
- const execSync = childProcess.execSync
11
- const exec = childProcess.exec
12
- const path = require('path')
5
+ import fs from 'fs'
6
+ import fse from 'fs-extra'
7
+ import fetch from 'node-fetch'
8
+ import { exec, execSync } from 'child_process'
9
+ import path from 'path'
10
+ import iconv from 'iconv-lite'
11
+ import opener from 'opener'
12
+ import clipboardy from 'clipboardy'
13
+ import assert from 'assert'
14
+ // 「標準入力取得時」で利用
15
+ import * as readline from 'readline'
16
+ import { stdin as input, stdout as output } from 'process'
17
+ // ハッシュ関数で利用
18
+ import crypto from 'crypto'
19
+ import os from 'os'
20
+ import sendkeysJS from 'sendkeys-js'
13
21
 
14
- const PluginNode = {
22
+ export default {
15
23
  '初期化': {
16
24
  type: 'func',
17
25
  josi: [],
18
26
  pure: true,
19
27
  fn: function (sys) {
20
- // ランタイム環境無しで実行する場合
21
- if (typeof path === 'undefined') {
22
- /** @param {string} name @param {string} id */
23
- const tryRequire = (name, id) => {
24
- try {
25
- // @ts-ignore
26
- global[name] = require(id)
27
- } catch (e) {
28
- console.warn(e.message)
29
- }
30
- }
31
- tryRequire('fs', 'fs')
32
- tryRequire('fse', 'fs-extra')
33
- tryRequire('fetch', 'node-fetch')
34
- tryRequire('childProcess', 'child_process')
35
- tryRequire('path', 'path')
36
- if (typeof childProcess !== 'undefined') {
37
- // @ts-ignore
38
- global.execSync = childProcess.execSync
39
- // @ts-ignore
40
- global.exec = childProcess.exec
41
- }
42
- }
43
-
44
28
  sys.__getBinPath = (tool) => {
45
29
  let fpath = tool
46
30
  if (process.platform === 'win32') {
@@ -109,7 +93,6 @@ const PluginNode = {
109
93
  josi: [['を', 'から']],
110
94
  pure: true,
111
95
  fn: function (s, sys) {
112
- const iconv = require('iconv-lite')
113
96
  iconv.skipDecodeWarning = true
114
97
  const buf = fs.readFileSync(s)
115
98
  const text = iconv.decode(Buffer.from(buf), 'sjis')
@@ -121,7 +104,6 @@ const PluginNode = {
121
104
  josi: [['を'], ['へ', 'に']],
122
105
  pure: true,
123
106
  fn: function (s, f, sys) {
124
- const iconv = require('iconv-lite')
125
107
  iconv.skipDecodeWarning = true
126
108
  const buf = iconv.encode(s, 'Shift_JIS')
127
109
  fs.writeFileSync(f, buf)
@@ -163,7 +145,6 @@ const PluginNode = {
163
145
  josi: [['を']],
164
146
  pure: true,
165
147
  fn: function (url) {
166
- const opener = require('opener')
167
148
  opener(url)
168
149
  }
169
150
  },
@@ -575,7 +556,6 @@ const PluginNode = {
575
556
  josi: [['を']],
576
557
  pure: true,
577
558
  fn: function (v, sys) {
578
- const clipboardy = require('clipboardy')
579
559
  // copy
580
560
  if (sys && sys.isSetter) { return clipboardy.writeSync(v) }
581
561
  // paste
@@ -591,7 +571,7 @@ const PluginNode = {
591
571
  josi: [['を']],
592
572
  pure: true,
593
573
  fn: function (callback) {
594
- const reader = require('readline').createInterface({
574
+ const reader = readline.createInterface({
595
575
  input: process.stdin,
596
576
  output: process.stdout
597
577
  })
@@ -604,9 +584,10 @@ const PluginNode = {
604
584
  type: 'func',
605
585
  josi: [['と', 'を']],
606
586
  pure: true,
607
- fn: function (msg, sys) {
608
- const readlineSync = require('readline-sync')
609
- const res = readlineSync.question(msg)
587
+ asyncFn: true,
588
+ fn: async function (msg, sys) {
589
+ const rl = readline.createInterface({ input, output });
590
+ const res = await rl.question(msg)
610
591
  if (res.match(/^[0-9.]+$/)) { return parseFloat(res) }
611
592
  return res
612
593
  }
@@ -617,7 +598,7 @@ const PluginNode = {
617
598
  josi: [['と'], ['が']],
618
599
  pure: true,
619
600
  fn: function (a, b, sys) {
620
- const assert = require('assert')
601
+
621
602
  assert.strictEqual(a, b)
622
603
  }
623
604
  },
@@ -627,7 +608,6 @@ const PluginNode = {
627
608
  josi: [],
628
609
  pure: true,
629
610
  fn: function (sys) {
630
- const os = require('os')
631
611
  const nif = os.networkInterfaces()
632
612
  /**
633
613
  * @type {string[]}
@@ -647,7 +627,6 @@ const PluginNode = {
647
627
  josi: [],
648
628
  pure: true,
649
629
  fn: function (sys) {
650
- const os = require('os')
651
630
  const nif = os.networkInterfaces()
652
631
  const result = []
653
632
  for (const dev in nif) {
@@ -925,7 +904,6 @@ const PluginNode = {
925
904
  josi: [['の', 'を']],
926
905
  pure: true,
927
906
  fn: function (code, sys) {
928
- const iconv = require('iconv-lite')
929
907
  return iconv.encodingExists(code)
930
908
  }
931
909
  },
@@ -934,7 +912,6 @@ const PluginNode = {
934
912
  josi: [['に', 'へ', 'を']],
935
913
  pure: true,
936
914
  fn: function (str, sys) {
937
- const iconv = require('iconv-lite')
938
915
  iconv.skipDecodeWarning = true
939
916
  return iconv.encode(str, 'Shift_JIS')
940
917
  }
@@ -944,7 +921,6 @@ const PluginNode = {
944
921
  josi: [['から', 'を', 'で']],
945
922
  pure: true,
946
923
  fn: function (buf, sys) {
947
- const iconv = require('iconv-lite')
948
924
  iconv.skipDecodeWarning = true
949
925
  return iconv.decode(Buffer.from(buf), 'sjis')
950
926
  }
@@ -954,7 +930,6 @@ const PluginNode = {
954
930
  josi: [['を'], ['へ', 'で']],
955
931
  pure: true,
956
932
  fn: function (s, code, sys) {
957
- const iconv = require('iconv-lite')
958
933
  iconv.skipDecodeWarning = true
959
934
  return iconv.encode(s, code)
960
935
  }
@@ -964,7 +939,6 @@ const PluginNode = {
964
939
  josi: [['を'], ['から', 'で']],
965
940
  pure: true,
966
941
  fn: function (buf, code, sys) {
967
- const iconv = require('iconv-lite')
968
942
  iconv.skipDecodeWarning = true
969
943
  return iconv.decode(Buffer.from(buf), code)
970
944
  }
@@ -975,8 +949,7 @@ const PluginNode = {
975
949
  josi: [['を', 'の']],
976
950
  pure: true,
977
951
  fn: function (s, sys) {
978
- const keys = require('sendkeys-js')
979
- keys.sendKeys(s)
952
+ sendkeysJS.sendKeys(s)
980
953
  },
981
954
  return_none: true
982
955
  },
@@ -985,8 +958,7 @@ const PluginNode = {
985
958
  josi: [['を', 'の']],
986
959
  pure: true,
987
960
  fn: function (s, sys) {
988
- const keys = require('sendkeys-js')
989
- keys.activate(s)
961
+ sendkeysJS.activate(s)
990
962
  },
991
963
  return_none: true
992
964
  },
@@ -996,7 +968,6 @@ const PluginNode = {
996
968
  josi: [],
997
969
  pure: true,
998
970
  fn: function (sys) {
999
- const crypto = require('crypto')
1000
971
  return crypto.getHashes()
1001
972
  }
1002
973
  },
@@ -1005,7 +976,6 @@ const PluginNode = {
1005
976
  josi: [['を'], ['の'], ['で']],
1006
977
  pure: true,
1007
978
  fn: function (s, alg, enc, sys) {
1008
- const crypto = require('crypto')
1009
979
  const hashsum = crypto.createHash(alg)
1010
980
  hashsum.update(s)
1011
981
  return hashsum.digest(enc)
@@ -1031,5 +1001,3 @@ function isDir (f) {
1031
1001
  return false
1032
1002
  }
1033
1003
  }
1034
-
1035
- module.exports = PluginNode
@@ -1,5 +1,5 @@
1
1
  // @ts-nocheck
2
- const PluginPromise = {
2
+ export default {
3
3
  '初期化': {
4
4
  type: 'func',
5
5
  josi: [],
@@ -90,5 +90,3 @@ const PluginPromise = {
90
90
  return_none: false
91
91
  }
92
92
  }
93
-
94
- module.exports = PluginPromise
@@ -1,8 +1,8 @@
1
1
  // @ts-nocheck
2
- const { NakoRuntimeError } = require('./nako_errors')
3
- const NakoVersion = require('./nako_version')
2
+ import { NakoRuntimeError } from './nako_errors.mjs'
3
+ import NakoVersion from './nako_version.mjs'
4
4
 
5
- const PluginSystem = {
5
+ export default {
6
6
  'meta': {
7
7
  type: 'const',
8
8
  value: {
@@ -2526,22 +2526,41 @@ const PluginSystem = {
2526
2526
  type: 'func',
2527
2527
  josi: [],
2528
2528
  pure: true,
2529
+ asyncFn: true,
2529
2530
  fn: function () {
2530
- const josi = require('./nako_josi_list.js')
2531
- return josi.josiList
2531
+ return new Promise((resolve, reject) => {
2532
+ import('./nako_josi_list.mjs')
2533
+ .then((mod) => {
2534
+ const obj = Object.assign({}, mod)
2535
+ resolve(obj.josiList)
2536
+ })
2537
+ .catch((err) => {
2538
+ reject(err)
2539
+ })
2540
+ })
2532
2541
  }
2533
2542
  },
2534
2543
  '予約語一覧取得': { // @文法として定義されている予約語の一覧を取得する // @よやくごいちらんしゅとく
2535
2544
  type: 'func',
2536
2545
  josi: [],
2537
2546
  pure: true,
2547
+ asyncFn: true,
2538
2548
  fn: function () {
2539
- const words = require('./nako_reserved_words.js')
2540
- const w = []
2541
- for (const key in words) {
2542
- w.push(key)
2543
- }
2544
- return w
2549
+ // const words = require('./nako_reserved_words.mjs')
2550
+ return new Promise((resolve, reject) => {
2551
+ import('./nako_reserved_words.mjs')
2552
+ .then((mod) => {
2553
+ const obj = Object.assign({}, mod)
2554
+ const w = []
2555
+ for (const key in obj.default) {
2556
+ w.push(key)
2557
+ }
2558
+ resolve(w)
2559
+ })
2560
+ .catch((err) => {
2561
+ reject(err)
2562
+ })
2563
+ })
2545
2564
  }
2546
2565
  },
2547
2566
  // @プラグイン管理
@@ -2603,7 +2622,7 @@ const PluginSystem = {
2603
2622
  pure: true,
2604
2623
  fn: function (text) {
2605
2624
  // browser?
2606
- if (window.btoa) {
2625
+ if (typeof(window) !== 'undefined' && window.btoa) {
2607
2626
  const utf8str = String.fromCharCode.apply(null, new TextEncoder('UTF-8').encode(text))
2608
2627
  return btoa(utf8str)
2609
2628
  } else {
@@ -2616,7 +2635,7 @@ const PluginSystem = {
2616
2635
  josi: [['を', 'へ', 'に']],
2617
2636
  pure: true,
2618
2637
  fn: function (text) {
2619
- if (window.atob) {
2638
+ if (typeof(window) !== 'undefined' && window.atob) {
2620
2639
  const decodedUtf8str = atob(text)
2621
2640
  const decodedArray = new Uint8Array(Array.prototype.map.call(decodedUtf8str, c => c.charCodeAt()))
2622
2641
  return new TextDecoder('UTF-8').decode(decodedArray)
@@ -2626,5 +2645,3 @@ const PluginSystem = {
2626
2645
  }
2627
2646
  }
2628
2647
  }
2629
-
2630
- module.exports = PluginSystem
@@ -3,7 +3,7 @@
3
3
  * file: plugin_test.js
4
4
  * テスト実行用プラグイン
5
5
  */
6
- const PluginTest = {
6
+ export default {
7
7
  // @テスト
8
8
  'ASSERT等': { // @ テストで、ASSERTでAとBが正しいことを報告する // @ASSERTひとしい
9
9
  type: 'func',
@@ -34,5 +34,3 @@ const PluginTest = {
34
34
  }
35
35
 
36
36
  }
37
-
38
- module.exports = PluginTest
@@ -4,9 +4,9 @@
4
4
  * plugin_turtle.js
5
5
  */
6
6
 
7
- const turtleImage = require('./turtle64.png').default
8
- const elephantImage = require('./turtle-elephant.png').default
9
- const pandaImage = require('./turtle-panda.png').default
7
+ import turtleImage from './image_turtle64.mjs'
8
+ import elephantImage from './image_turtle-elephant.mjs'
9
+ import pandaImage from './image_turtle-panda.mjs'
10
10
 
11
11
  const PluginTurtle = {
12
12
  '初期化': {
@@ -639,7 +639,8 @@ const PluginTurtle = {
639
639
  }
640
640
  }
641
641
 
642
- module.exports = PluginTurtle
642
+ // module.exports = PluginTurtle
643
+ export default PluginTurtle
643
644
 
644
645
  // scriptタグで取り込んだ時、自動で登録する
645
646
  /* istanbul ignore else */
@@ -326,9 +326,9 @@ const PluginWebWorker = {
326
326
  }
327
327
  }
328
328
 
329
+ export default PluginWebWorker
330
+
329
331
  if (typeof (navigator) === 'object' && typeof (navigator.nako3) === 'object') {
330
332
  navigator.nako3.addPluginObject('PluginWebWorker', PluginWebWorker)
331
333
  }
332
- if (typeof (module) === 'object') {
333
- module.exports = PluginWebWorker
334
- }
334
+
@@ -1206,9 +1206,7 @@ const PluginWeykTurtle3D = {
1206
1206
  }
1207
1207
  }
1208
1208
 
1209
- if (typeof (global) === 'object' && typeof (global.process) === 'object') {
1210
- module.exports = PluginWeykTurtle3D
1211
- }
1209
+ export default PluginWeykTurtle3D
1212
1210
 
1213
1211
  // ブラウザからscriptタグで取り込んだ時、自動で登録する
1214
1212
  if (typeof (navigator) === 'object') {
@@ -89,4 +89,7 @@ const PluginWorker = {
89
89
  }
90
90
  }
91
91
 
92
- module.exports = PluginWorker
92
+ // module.exports = PluginWorker
93
+ export default PluginWorker
94
+
95
+
@@ -1,13 +1,13 @@
1
1
  // @ts-nocheck
2
2
  // nadesiko for web browser
3
3
  // wnako3.js
4
- require('whatwg-fetch') // IE11サポートが不要になったら外す
5
4
 
6
- const NakoCompiler = require('./nako3')
7
- const { NakoImportError } = require('./nako_errors')
5
+ import { NakoCompiler } from './nako3.mjs'
6
+ import { NakoImportError } from './nako_errors.mjs'
7
+ import { setupEditor } from './wnako3_editor.mjs'
8
+ import PluginBrowser from './plugin_browser.mjs'
9
+
8
10
  const NAKO_SCRIPT_RE = /^(なでしこ|nako|nadesiko)3?$/
9
- const { setupEditor } = require('./wnako3_editor')
10
- const PluginBrowser = require('./plugin_browser')
11
11
 
12
12
  class WebNakoCompiler extends NakoCompiler {
13
13
  constructor () {
@@ -2,11 +2,17 @@
2
2
  /* eslint-disable no-template-curly-in-string */
3
3
  /** なでしこのtokenのtypeをscope(CSSのクラス名)に変換する。 */
4
4
 
5
- const { OffsetToLineColumn } = require('./nako_source_mapping')
6
- const { NakoError } = require('./nako_errors')
7
- const { getBlockStructure, getIndent, countIndent, isIndentSyntaxEnabled } = require('./nako_indent')
8
- const NakoPrepare = require('./nako_prepare')
9
- const NakoLogger = require('./nako_logger')
5
+ import { OffsetToLineColumn } from './nako_source_mapping.mjs'
6
+ import { NakoError } from './nako_errors.mjs'
7
+ import NakoIndent from './nako_indent.mjs'
8
+ import { NakoPrepare } from './nako_prepare.mjs'
9
+ import { NakoLogger } from './nako_logger.mjs'
10
+
11
+ // alias
12
+ const getBlockStructure = NakoIndent.getBlockStructure
13
+ const getIndent = NakoIndent.getIndent
14
+ const countIndent = NakoIndent.countIndent
15
+ const isIndentSyntaxEnabled = NakoIndent.isIndentSyntaxEnabled
10
16
 
11
17
  /**
12
18
  * @typedef {import('./nako3')} NakoCompiler
@@ -69,7 +75,7 @@ const NakoLogger = require('./nako_logger')
69
75
  * @param {TokenWithSourceMap} token
70
76
  * @returns {TokenType}
71
77
  */
72
- function getScope (token) {
78
+ export function getScope (token) {
73
79
  switch (token.type) {
74
80
  case 'line_comment': return 'comment.line'
75
81
  case 'range_comment': return 'comment.block'
@@ -154,7 +160,7 @@ function getScope (token) {
154
160
  * @param {boolean} includesLastCharacter
155
161
  * @param {boolean} underlineJosi
156
162
  */
157
- function getEditorTokens (compilerToken, nako3, value, includesLastCharacter, underlineJosi) {
163
+ export function getEditorTokens (compilerToken, nako3, value, includesLastCharacter, underlineJosi) {
158
164
  const type = getScope(compilerToken)
159
165
  const docHTML = getDocumentationHTML(compilerToken, nako3)
160
166
 
@@ -177,7 +183,7 @@ function getEditorTokens (compilerToken, nako3, value, includesLastCharacter, un
177
183
  * @param {NakoCompiler} nako3
178
184
  * @returns {string | null}
179
185
  */
180
- function findPluginName (name, nako3) {
186
+ export function findPluginName (name, nako3) {
181
187
  for (const pluginName of Object.keys(nako3.__module)) {
182
188
  if (Object.keys(nako3.__module[pluginName]).includes(name)) {
183
189
  return pluginName
@@ -191,7 +197,7 @@ function findPluginName (name, nako3) {
191
197
  * @param {number} i
192
198
  * @returns {string}
193
199
  */
194
- function createParameterName (i) {
200
+ export function createParameterName (i) {
195
201
  const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
196
202
  return i.toString(26).split('').map((v) => alphabet[parseInt(v, 26)]).join('')
197
203
  }
@@ -201,7 +207,7 @@ function createParameterName (i) {
201
207
  * @param {string[][]} josi
202
208
  * @retunrs {string}
203
209
  */
204
- function createParameterDeclaration (josi) {
210
+ export function createParameterDeclaration (josi) {
205
211
  const args = josi.map((union, i) => union.map((v) => `${createParameterName(i)}${v}`).join('|')).join('、')
206
212
  if (args !== '') {
207
213
  return `(${args})`
@@ -212,7 +218,7 @@ function createParameterDeclaration (josi) {
212
218
 
213
219
  // https://stackoverflow.com/a/6234804
214
220
  /** @param {string} t */
215
- function escapeHTML (t) {
221
+ export function escapeHTML (t) {
216
222
  return t
217
223
  .replace(/&/g, '&')
218
224
  .replace(/</g, '&lt;')
@@ -227,7 +233,7 @@ function escapeHTML (t) {
227
233
  * @param {NakoCompiler} nako3
228
234
  * @returns {string | null}
229
235
  */
230
- function getDocumentationHTML (token, nako3) {
236
+ export function getDocumentationHTML (token, nako3) {
231
237
  /** @param {string} text */
232
238
  const meta = (text) => `<span class="tooltip-plugin-name">${escapeHTML(text)}</span>`
233
239
  if (token.type === 'func') {
@@ -277,7 +283,7 @@ const withoutLogger = (nako3, f) => {
277
283
  * @param {NakoCompiler} nako3
278
284
  * @param {boolean} underlineJosi
279
285
  */
280
- function tokenize (lines, nako3, underlineJosi) {
286
+ export function tokenize (lines, nako3, underlineJosi) {
281
287
  const code = lines.join('\n')
282
288
 
283
289
  // 取り込み文を含めてしまうと依存ファイルが大きい時に時間がかかってしまうため、
@@ -399,7 +405,7 @@ function tokenize (lines, nako3, underlineJosi) {
399
405
  /**
400
406
  * エディタ上にエラーメッセージの波線とgutterの赤いマークとエラーメッセージのポップアップを設定するためのクラス。
401
407
  */
402
- class EditorMarkers {
408
+ export class EditorMarkers {
403
409
  /**
404
410
  * @param {any} session
405
411
  * @param {AceDocument} doc
@@ -521,7 +527,7 @@ class EditorMarkers {
521
527
  * ace editor ではシンタックスハイライトのために正規表現ベースのBackgroundTokenizerクラスを用意し定期的にトークン化を
522
528
  * 行っているが、正規表現ではなくなでしこのコンパイラの出力を使うためにはそれを上書きする必要がある。
523
529
  */
524
- class BackgroundTokenizer {
530
+ export class BackgroundTokenizer {
525
531
  /**
526
532
  * @param {AceDocument} doc
527
533
  * @param {NakoCompiler} nako3
@@ -699,7 +705,7 @@ class BackgroundTokenizer {
699
705
  /**
700
706
  * シンタックスハイライト以外のエディタの挙動の定義。
701
707
  */
702
- class LanguageFeatures {
708
+ export class LanguageFeatures {
703
709
  /**
704
710
  * @param {TypeofAceRange} AceRange
705
711
  * @param {NakoCompiler} nako3
@@ -1287,7 +1293,7 @@ let editorIdCounter = 0
1287
1293
  * @param {import('./wnako3')} nako3
1288
1294
  * @param {any} ace
1289
1295
  */
1290
- function setupEditor (idOrElement, nako3, ace) {
1296
+ export function setupEditor (idOrElement, nako3, ace) {
1291
1297
  /** @type {AceEditor} */
1292
1298
  const editor = ace.edit(idOrElement)
1293
1299
  const element = typeof idOrElement === 'string' ? document.getElementById(idOrElement) : idOrElement
@@ -1636,7 +1642,7 @@ function setupEditor (idOrElement, nako3, ace) {
1636
1642
  return { editor, editorMarkers, editorTabs, retokenize, run, codeLensListeners }
1637
1643
  }
1638
1644
 
1639
- module.exports = {
1645
+ export default {
1640
1646
  tokenize,
1641
1647
  setupEditor,
1642
1648
  LanguageFeatures,
File without changes
@@ -1,11 +1,10 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3.js')
3
- const NakoGenAsync = require('../../src/nako_gen_async.js')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import { NakoGenASync } from '../../src/nako_gen_async.mjs'
4
4
 
5
5
  describe('aysnc_basic_test', () => {
6
6
  // @ts-ignore
7
7
  const nako = new NakoCompiler()
8
- nako.addCodeGenerator('非同期モード', NakoGenAsync)
9
8
  const cmp = (/** @type {string} */code, /** @type {string} */res) => {
10
9
  code = '!非同期モード\n' + code
11
10
  nako.logger.debug('code=' + code)
@@ -1,3 +1,12 @@
1
+ /*
2
+ import express from 'express'
3
+ import path from 'path'
4
+ import multer from 'multer'
5
+ import bodyParserRaw from 'body-parser/lib/types/raw.js'
6
+ import bodyParserText from 'body-parser/lib/types/text.js'
7
+ import bodyParserUrlencoded =from 'body-parser/lib/types/urlencoded.js'
8
+ */
9
+
1
10
  const multer = require('multer')
2
11
  const bodyParserRaw = require('body-parser/lib/types/raw')
3
12
  const bodyParserText = require('body-parser/lib/types/text')
@@ -1,6 +1,6 @@
1
1
  import 'whatwg-fetch'
2
- import NakoCompiler from 'nako3/nako3.js'
3
- import PluginBrowser from 'nako3/plugin_browser.js'
2
+ import { NakoCompiler } from 'nako3/nako3.mjs'
3
+ import PluginBrowser from 'nako3/plugin_browser.mjs'
4
4
 
5
5
  import browserTestColor from './plugin_browser_test_color.js'
6
6
  import browserTestSystem from './plugin_browser_test_system.js'
@@ -1,8 +1,8 @@
1
1
  /* global __html__ */
2
2
  import { assert } from 'chai'
3
- import NakoCompiler from 'nako3/nako3.js'
3
+ import { NakoCompiler } from 'nako3/nako3.mjs'
4
4
  import { importStatus } from './import_plugin_checker.js'
5
- import PluginTurtle from 'nako3/plugin_turtle'
5
+ import PluginTurtle from 'nako3/plugin_turtle.mjs'
6
6
 
7
7
  const htmlPath = 'test/html/'
8
8
  const imagePath = '/test/image/'
@@ -1,9 +1,9 @@
1
1
  import 'whatwg-fetch'
2
2
  import { assert } from 'chai'
3
- import NakoCompiler from 'nako3/nako3.js'
4
- import PluginBrowser from 'nako3/plugin_browser'
3
+ import { NakoCompiler } from 'nako3/nako3.mjs'
4
+ import PluginBrowser from 'nako3/plugin_browser.mjs'
5
5
  import { importStatus } from './import_plugin_checker.js'
6
- import PluginWebWorker from 'nako3/plugin_webworker'
6
+ import PluginWebWorker from 'nako3/plugin_webworker.mjs'
7
7
  import { retry } from './compare_util'
8
8
 
9
9
  describe('plugin_webworker_test', () => {
@@ -1,8 +1,8 @@
1
1
  import { assert } from 'chai'
2
- import { NakoImportError } from 'nako3/nako_errors'
2
+ import { NakoImportError } from 'nako3/nako_errors.mjs'
3
3
 
4
4
  navigator.exportWNako3 = true
5
- const WebNakoCompiler = require('nako3/wnako3')
5
+ const WebNakoCompiler = require('nako3/wnako3.mjs')
6
6
  navigator.exportWNako3 = false
7
7
 
8
8
  /**
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const { expect } = require('chai')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import { expect } from 'chai'
4
4
 
5
5
  describe('array_test', () => {
6
6
  const nako = new NakoCompiler()
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const { expect } = require('chai')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import { expect } from 'chai'
4
4
 
5
5
  describe('basic', () => {
6
6
  const nako = new NakoCompiler()
@@ -255,16 +255,6 @@ describe('basic', () => {
255
255
  , 'main.nako3')
256
256
  assert.strictEqual(log, '')
257
257
  })
258
- it('単独で実行できるプログラムの出力', function (done) {
259
- if (typeof process === 'undefined' || process.env.NODE_ENV === 'test') {return this.skip()}
260
- const code = nako.compileStandalone('1+2を表示', 'main.nako3', false)
261
- Function('const console = { log: this.callback };\n' + code).apply({
262
- callback: (/** @type {any} */text) => {
263
- assert.strictEqual(text, '3')
264
- done()
265
- },
266
- })
267
- })
268
258
  it('resetされた後に関数名を取得できない問題の修正 #849', (done) => {
269
259
  const nako = new NakoCompiler()
270
260
  nako.logger.addListener('stdout', ({ noColor }) => {