nadesiko3 3.2.52 → 3.3.3

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 (178) 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/runscript3.html +35 -0
  7. package/demo/turtle3.html +18 -17
  8. package/demo/turtle3d.html +1 -1
  9. package/demo/turtle3d2.html +1 -1
  10. package/doc/browsers.md +9 -10
  11. package/package.json +58 -57
  12. package/release/_hash.txt +57 -52
  13. package/release/_script-tags.txt +14 -13
  14. package/release/command.json +1 -1
  15. package/release/command.json.js +1 -1
  16. package/release/command_cnako3.json +1 -1
  17. package/release/command_list.json +1 -1
  18. package/release/editor.js +1 -1
  19. package/release/editor.js.LICENSE.txt +9 -12
  20. package/release/nako_gen_async.js +1 -1
  21. package/release/nako_gen_async.js.LICENSE.txt +10 -666
  22. package/release/plugin_caniuse.js +1 -1
  23. package/release/plugin_caniuse.js.LICENSE.txt +9 -425
  24. package/release/plugin_csv.js +1 -1
  25. package/release/plugin_csv.js.LICENSE.txt +3 -419
  26. package/release/plugin_datetime.js +1 -1
  27. package/release/plugin_datetime.js.LICENSE.txt +6 -530
  28. package/release/plugin_kansuji.js +1 -1
  29. package/release/plugin_kansuji.js.LICENSE.txt +3 -559
  30. package/release/plugin_markup.js +1 -1
  31. package/release/plugin_markup.js.LICENSE.txt +4 -420
  32. package/release/plugin_turtle.js +1 -1
  33. package/release/plugin_turtle.js.LICENSE.txt +12 -500
  34. package/release/plugin_webworker.js +1 -1
  35. package/release/plugin_webworker.js.LICENSE.txt +3 -563
  36. package/release/plugin_weykturtle3d.js +1 -0
  37. package/release/plugin_weykturtle3d.js.LICENSE.txt +3 -0
  38. package/release/stats.json +1 -1
  39. package/release/version.js +1 -1
  40. package/release/version.js.LICENSE.txt +9 -12
  41. package/release/wnako3.js +1 -1
  42. package/release/wnako3.js.LICENSE.txt +1 -1
  43. package/release/wnako3webworker.js +1 -1
  44. package/release/wnako3webworker.js.LICENSE.txt +1 -1117
  45. package/src/browsers.mjs +1 -0
  46. package/src/browsers.txt +15 -15
  47. package/src/browsers_agents.mjs +1 -0
  48. package/src/cnako3.mjs +13 -0
  49. package/src/{cnako3.js → cnako3mod.mjs} +119 -101
  50. package/src/{commander_ja.js → commander_ja.mjs} +16 -11
  51. package/src/{enako3.js → enako3.mjs} +0 -0
  52. package/src/{era.json → era.mjs} +1 -1
  53. package/src/image_turtle-elephant.mjs +5 -0
  54. package/src/image_turtle-panda.mjs +5 -0
  55. package/src/image_turtle64.mjs +5 -0
  56. package/src/index.mjs +9 -0
  57. package/src/{nako3.js → nako3.mjs} +69 -57
  58. package/src/{nako3_assert.js → nako3_assert.mjs} +7 -6
  59. package/src/{nako3server.js → nako3server.mjs} +12 -5
  60. package/src/{nako_colors.js → nako_colors.mjs} +1 -1
  61. package/src/{nako_errors.js → nako_errors.mjs} +10 -20
  62. package/src/{nako_from_dncl.js → nako_from_dncl.mjs} +11 -8
  63. package/src/{nako_gen.js → nako_gen.mjs} +93 -87
  64. package/src/{nako_gen_async.js → nako_gen_async.mjs} +5 -8
  65. package/src/{nako_global.js → nako_global.mjs} +4 -5
  66. package/src/{nako_indent.js → nako_indent.mjs} +29 -25
  67. package/src/{nako_josi_list.js → nako_josi_list.mjs} +16 -14
  68. package/src/nako_lex_rules.mjs +244 -0
  69. package/src/{nako_lexer.js → nako_lexer.mjs} +7 -10
  70. package/src/{nako_logger.js → nako_logger.mjs} +3 -4
  71. package/src/{nako_parser3.js → nako_parser3.mjs} +5 -5
  72. package/src/{nako_parser_base.js → nako_parser_base.mjs} +1 -9
  73. package/src/{nako_parser_const.js → nako_parser_const.mjs} +2 -6
  74. package/src/{nako_prepare.js → nako_prepare.mjs} +46 -8
  75. package/src/{nako_reserved_words.js → nako_reserved_words.mjs} +1 -1
  76. package/src/{nako_source_mapping.js → nako_source_mapping.mjs} +4 -11
  77. package/src/{nako_test.js → nako_test.mjs} +0 -0
  78. package/src/nako_version.mjs +7 -0
  79. package/src/{plugin_browser.js → plugin_browser.mjs} +30 -30
  80. package/src/{plugin_browser_ajax.js → plugin_browser_ajax.mjs} +7 -7
  81. package/src/{plugin_browser_audio.js → plugin_browser_audio.mjs} +1 -1
  82. package/src/{plugin_browser_canvas.js → plugin_browser_canvas.mjs} +1 -1
  83. package/src/{plugin_browser_chart.js → plugin_browser_chart.mjs} +1 -1
  84. package/src/{plugin_browser_color.js → plugin_browser_color.mjs} +1 -1
  85. package/src/{plugin_browser_crypto.js → plugin_browser_crypto.mjs} +1 -1
  86. package/src/{plugin_browser_dialog.js → plugin_browser_dialog.mjs} +1 -1
  87. package/src/{plugin_browser_dom_basic.js → plugin_browser_dom_basic.mjs} +1 -1
  88. package/src/{plugin_browser_dom_event.js → plugin_browser_dom_event.mjs} +1 -1
  89. package/src/{plugin_browser_dom_parts.js → plugin_browser_dom_parts.mjs} +1 -1
  90. package/src/{plugin_browser_geolocation.js → plugin_browser_geolocation.mjs} +1 -1
  91. package/src/{plugin_browser_hotkey.js → plugin_browser_hotkey.mjs} +2 -2
  92. package/src/{plugin_browser_html.js → plugin_browser_html.mjs} +1 -1
  93. package/src/{plugin_browser_in_worker.js → plugin_browser_in_worker.mjs} +4 -4
  94. package/src/{plugin_browser_location.js → plugin_browser_location.mjs} +1 -1
  95. package/src/{plugin_browser_speech.js → plugin_browser_speech.mjs} +1 -1
  96. package/src/{plugin_browser_storage.js → plugin_browser_storage.mjs} +1 -1
  97. package/src/{plugin_browser_system.js → plugin_browser_system.mjs} +1 -1
  98. package/src/{plugin_browser_websocket.js → plugin_browser_websocket.mjs} +1 -1
  99. package/src/{plugin_caniuse.js → plugin_caniuse.mjs} +8 -3
  100. package/src/{plugin_csv.js → plugin_csv.mjs} +4 -5
  101. package/src/{plugin_datetime.js → plugin_datetime.mjs} +19 -26
  102. package/src/{plugin_express.js → plugin_express.mjs} +4 -3
  103. package/src/{plugin_kansuji.js → plugin_kansuji.mjs} +1 -1
  104. package/src/{plugin_keigo.js → plugin_keigo.mjs} +1 -1
  105. package/src/{plugin_markup.js → plugin_markup.mjs} +6 -6
  106. package/src/{plugin_math.js → plugin_math.mjs} +1 -4
  107. package/src/{plugin_node.js → plugin_node.mjs} +25 -57
  108. package/src/{plugin_promise.js → plugin_promise.mjs} +1 -3
  109. package/src/{plugin_system.js → plugin_system.mjs} +32 -15
  110. package/src/{plugin_test.js → plugin_test.mjs} +1 -3
  111. package/src/{plugin_turtle.js → plugin_turtle.mjs} +5 -4
  112. package/src/{plugin_webworker.js → plugin_webworker.mjs} +3 -3
  113. package/src/{plugin_weykturtle3d.js → plugin_weykturtle3d.mjs} +1 -3
  114. package/src/{plugin_worker.js → plugin_worker.mjs} +4 -1
  115. package/src/{wnako3.js → wnako3.mjs} +24 -14
  116. package/src/{wnako3_editor.js → wnako3_editor.mjs} +28 -22
  117. package/src/{wnako3webworker.js → wnako3webworker.mjs} +0 -0
  118. package/test/async/{async_basic_test.js → async_basic_test.mjs} +3 -4
  119. package/test/browser/karma.config.js +9 -0
  120. package/test/browser/test/plugin_browser_test.js +2 -2
  121. package/test/browser/test/plugin_turtle_test.js +2 -2
  122. package/test/browser/test/plugin_webworker_test.js +3 -3
  123. package/test/browser/test/require_test.js +2 -2
  124. package/test/common/{array_test.js → array_test.mjs} +3 -3
  125. package/test/common/{basic_test.js → basic_test.mjs} +3 -13
  126. package/test/common/{calc_test.js → calc_test.mjs} +2 -2
  127. package/test/common/{debug_test.js → debug_test.mjs} +2 -2
  128. package/test/common/{dncl_test.js → dncl_test.mjs} +3 -3
  129. package/test/common/{error_test.js → error_test.mjs} +2 -2
  130. package/test/common/{flow_test.js → flow_test.mjs} +2 -2
  131. package/test/common/{func_call.js → func_call.mjs} +3 -3
  132. package/test/common/{func_test.js → func_test.mjs} +2 -2
  133. package/test/common/{indent_test.js → indent_test.mjs} +3 -2
  134. package/test/common/{lex_test.js → lex_test.mjs} +2 -2
  135. package/test/common/{literal_test.js → literal_test.mjs} +3 -2
  136. package/test/common/{nako_logger_test.js → nako_logger_test.mjs} +3 -3
  137. package/test/common/{plugin_browser_test.js → plugin_browser_test.mjs} +4 -4
  138. package/test/common/{plugin_browser_ut_audio_test.js → plugin_browser_ut_audio_test.mjs} +4 -4
  139. package/test/common/{plugin_browser_ut_color_test.js → plugin_browser_ut_color_test.mjs} +2 -2
  140. package/test/common/{plugin_browser_ut_dialog_test.js → plugin_browser_ut_dialog_test.mjs} +3 -3
  141. package/test/common/{plugin_browser_ut_html_test.js → plugin_browser_ut_html_test.mjs} +2 -2
  142. package/test/common/{plugin_browser_ut_system_test.js → plugin_browser_ut_system_test.mjs} +2 -2
  143. package/test/common/{plugin_csv_test.js → plugin_csv_test.mjs} +3 -3
  144. package/test/common/{plugin_datetime_test.js → plugin_datetime_test.mjs} +4 -4
  145. package/test/common/{plugin_kansuji_test.js → plugin_kansuji_test.mjs} +3 -3
  146. package/test/common/{plugin_markup_test.js → plugin_markup_test.mjs} +3 -3
  147. package/test/common/{plugin_promise_test.js → plugin_promise_test.mjs} +2 -2
  148. package/test/common/{plugin_system_test.js → plugin_system_test.mjs} +2 -2
  149. package/test/common/{prepare_test.js → prepare_test.mjs} +2 -2
  150. package/test/common/{re_test.js → re_test.mjs} +2 -2
  151. package/test/common/{variable_scope_test.js → variable_scope_test.mjs} +2 -2
  152. package/test/karma.config.js +3 -3
  153. package/test/node/{async_test.js → async_test.mjs} +4 -2
  154. package/test/node/{commander_ja_test.js → commander_ja_test.mjs} +17 -12
  155. package/test/node/{error_message_test.js → error_message_test.mjs} +13 -10
  156. package/test/node/node_test.mjs +57 -0
  157. package/test/node/{plugin_browser_ut_ajax_test.js → plugin_browser_ut_ajax_test.mjs} +7 -5
  158. package/test/node/{plugin_browser_ut_location_test.js → plugin_browser_ut_location_test.mjs} +3 -3
  159. package/test/node/{plugin_markup_test.js → plugin_markup_test.mjs} +6 -7
  160. package/test/node/{plugin_math_test.js → plugin_math_test.mjs} +5 -5
  161. package/test/node/{plugin_node_test.js → plugin_node_test.mjs} +11 -7
  162. package/test/node/{plugin_test.js → plugin_test.mjs} +11 -5
  163. package/test/node/{require_nako3_test.js → require_nako3_test.mjs} +19 -12
  164. package/test/node/{side_effects_test.js → side_effects_test.mjs} +24 -13
  165. package/test/node/{wnako3_editor_test.js → wnako3_editor_test.mjs} +16 -9
  166. package/tools/nako3edit/html/daisyui/LICENSE +22 -0
  167. package/tools/nako3edit/html/daisyui/full.css +1 -0
  168. package/tools/nako3edit/html/daisyui/tailwind.min.css +1 -0
  169. package/tools/nako3edit/html/daisyui/version_2.14.1 +1 -0
  170. package/tools/nako3edit/html/edit.html +104 -19
  171. package/tools/nako3edit/html/files.html +84 -8
  172. package/tools/nako3edit/html/nako3edit.css +6 -7
  173. package/tools/nako3edit/index.nako3 +45 -6
  174. package/tools/nako3edit/{run.js → run.mjs} +8 -2
  175. package/src/index.js +0 -5
  176. package/src/nako_lex_rules.js +0 -260
  177. package/src/nako_version.js +0 -8
  178. package/test/node/node_test.js +0 -43
@@ -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 () {
@@ -18,7 +18,7 @@ class WebNakoCompiler extends NakoCompiler {
18
18
  /**
19
19
  * ブラウザでtype="なでしこ"というスクリプトを得て実行する
20
20
  */
21
- runNakoScript () {
21
+ async runNakoScript () {
22
22
  // スクリプトタグの中身を得る
23
23
  let nakoScriptCount = 0
24
24
  const scripts = document.querySelectorAll('script')
@@ -26,7 +26,14 @@ class WebNakoCompiler extends NakoCompiler {
26
26
  const script = scripts[i]
27
27
  if (script.type.match(NAKO_SCRIPT_RE)) {
28
28
  nakoScriptCount++
29
- this.run(script.text, `script${i}.nako3`)
29
+ // URLからスクリプト名を見つける
30
+ const url = (typeof(window.location) == 'object') ? window.location.href : 'url_unknown'
31
+ const fname = `${url}#script${nakoScriptCount}.nako3`
32
+ const code = script.text
33
+ // 依存するライブラリをロード
34
+ await this.loadDependencies(code, fname)
35
+ // プログラムを実行
36
+ this.run(script.text, fname)
30
37
  }
31
38
  }
32
39
  console.log('実行したなでしこの個数=', nakoScriptCount)
@@ -59,11 +66,11 @@ class WebNakoCompiler extends NakoCompiler {
59
66
  value: (async () => {
60
67
  const res = await fetch(filePath)
61
68
  if (!res.ok) {
62
- throw new NakoImportError(`ファイル ${filePath} のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.line, token.file)
69
+ throw new NakoImportError(`ファイル『${filePath}』のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.file, token.line)
63
70
  }
64
71
  const text = await res.text()
65
72
  if (!text.includes('navigator.nako3.addPluginObject')) {
66
- throw new NakoImportError(`ファイル ${filePath} の中に文字列 "navigator.nako3.addPluginObject" が存在しません。現在、ブラウザ版のなでしこ言語v3は自動登録するプラグインのみをサポートしています。`, token.line, token.file)
73
+ throw new NakoImportError(`ファイル ${filePath} の中に文字列 "navigator.nako3.addPluginObject" が存在しません。現在、ブラウザ版のなでしこ言語v3は自動登録するプラグインのみをサポートしています。`, token.file, token.line)
67
74
  }
68
75
  // textの例: `navigator.nako3.addPluginObject('PluginRequireTest', { requiretest: { type: 'var', value: 100 } })`
69
76
  return () => {
@@ -74,7 +81,7 @@ class WebNakoCompiler extends NakoCompiler {
74
81
  // eslint-disable-next-line no-new-func
75
82
  Function(text)()
76
83
  } catch (err) {
77
- throw new NakoImportError(`プラグイン ${filePath} の取り込みに失敗: ${err instanceof Error ? err.message : err + ''}`, token.line, token.file)
84
+ throw new NakoImportError(`プラグイン ${filePath} の取り込みに失敗: ${err instanceof Error ? err.message : err + ''}`, token.file, token.line)
78
85
  } finally {
79
86
  navigator.nako3 = globalNako3
80
87
  }
@@ -93,7 +100,7 @@ class WebNakoCompiler extends NakoCompiler {
93
100
  value: (async () => {
94
101
  const res = await fetch(filePath)
95
102
  if (!res.ok) {
96
- throw new NakoImportError(`ファイル ${filePath} のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.line, token.file)
103
+ throw new NakoImportError(`ファイル ${filePath} のダウンロードに失敗しました: ${res.status} ${res.statusText}`, token.file, token.line)
97
104
  }
98
105
  return await res.text()
99
106
  })()
@@ -114,17 +121,20 @@ class WebNakoCompiler extends NakoCompiler {
114
121
  const href = href_dir + '/' + name
115
122
  pathname = new URL(href).pathname
116
123
  } catch (e) {
117
- throw new NakoImportError(`取り込み文の引数でパスが解決できません。https:// か http:// で始まるアドレスを指定してください。\n${e}`, token.line, token.file)
124
+ throw new NakoImportError(`取り込み文の引数でパスが解決できません。https:// か http:// で始まるアドレスを指定してください。\n${e}`, token.file, token.line)
118
125
  }
119
126
  }
120
127
  }
121
- if (pathname.endsWith('.js') || pathname.endsWith('.js.txt')) {
128
+ // .js および .mjs なら JSプラグイン
129
+ if (pathname.endsWith('.js') || pathname.endsWith('.js.txt') || pathname.endsWith('.mjs') || pathname.endsWith('.mjs.txt')) {
122
130
  return { filePath: name, type: 'js' }
123
131
  }
132
+ // .nako3 なら なでしこ3プラグイン
124
133
  if (pathname.endsWith('.nako3') || pathname.endsWith('.nako3.txt')) {
125
134
  return { filePath: name, type: 'nako3' }
126
135
  }
127
- return { filePath: name, type: 'invalid' }
136
+ // ファイル拡張子が未指定の場合
137
+ throw new NakoImportError(`ファイル『${name}』は拡張子が(.nako3|.js|.js.txt|.mjs|.mjs.txt)以外なので取り込めません。`, token.file, token.line)
128
138
  }
129
139
  })
130
140
  }
@@ -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
@@ -717,7 +723,7 @@ class LanguageFeatures {
717
723
  * @param {number} endRow
718
724
  */
719
725
  static toggleCommentLines (state, { doc }, startRow, endRow) {
720
- const prepare = new NakoPrepare(new NakoLogger())
726
+ const prepare = NakoPrepare.getInstance(new NakoLogger())
721
727
  /**
722
728
  * @param {string} line
723
729
  * @returns {{ type: 'blank' | 'code' } | { type: 'comment', start: number, len: number }}
@@ -728,11 +734,11 @@ class LanguageFeatures {
728
734
  if (indent === line) {
729
735
  return { type: 'blank' }
730
736
  }
731
- line = line.substr(indent.length)
737
+ line = line.substring(indent.length)
732
738
 
733
739
  // 先頭がコメントの開始文字かどうか確認する
734
- const ch2 = line.substr(0, 2).split('').map((c) => prepare.convert1ch(c)).join('')
735
- if (ch2.substr(0, 1) === '#') {
740
+ const ch2 = line.substring(0, 2).split('').map((c) => prepare.convert1ch(c)).join('')
741
+ if (ch2.substring(0, 1) === '#') {
736
742
  return { type: 'comment', start: indent.length, len: 1 + (line.charAt(1) === ' ' ? 1 : 0) }
737
743
  }
738
744
  if (ch2 === '//') {
@@ -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 }) => {
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('calc_test.js', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('debug', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoDncl = require('../../src/nako_from_dncl')
3
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import { NakoDncl } from '../../src/nako_from_dncl.mjs'
4
4
 
5
5
  describe('dncl (#1140)', () => {
6
6
  const cmp = (src, expected) => {
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('error_test', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('flow_test', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const NakoSyntaxError = require('../../src/nako_parser_base').NakoSyntaxError
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import { NakoSyntaxError } from '../../src/nako_errors.mjs'
4
4
 
5
5
  describe('関数呼び出しテスト', () => {
6
6
  const nako = new NakoCompiler()
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('func_test', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,5 +1,6 @@
1
- const assert = require('assert')
2
- const NakoIndent = require('../../src/nako_indent')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import NakoIndent from '../../src/nako_indent.mjs'
3
4
 
4
5
  describe('indent', () => {
5
6
  const cmp = (src, expected) => {
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('lex_test', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,5 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+
3
4
  describe('literal_test', () => {
4
5
  const nako = new NakoCompiler()
5
6
  // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
@@ -1,6 +1,6 @@
1
- const NakoColors = require('../../src/nako_colors')
2
- const assert = require('assert')
3
- const NakoLogger = require('root/src/nako_logger')
1
+ import assert from 'assert'
2
+ import { NakoColors } from '../../src/nako_colors.mjs'
3
+ import { NakoLogger } from '../../src/nako_logger.mjs'
4
4
 
5
5
  describe('nako_logger_test', () => {
6
6
  it('色付けのテスト', () => {
@@ -1,9 +1,9 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const PluginBrowser = require('../../src/plugin_browser')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import PluginBrowser from '../../src/plugin_browser.mjs'
4
4
 
5
5
  describe('plugin_browser_test', () => {
6
- const nako = new NakoCompiler()
6
+ const nako = new NakoCompiler({useBasicPlugin: true})
7
7
  // nako.logger.addListener('trace', ({ browserConsole }) => { console.log(...browserConsole) })
8
8
  nako.addPluginFile('PluginBrowser', 'plugin_browser.js', PluginBrowser)
9
9
  const cmp = (code, res) => {
@@ -1,7 +1,7 @@
1
- const td = require('testdouble')
2
- const assert = require('assert').strict
3
- const PluginBrowser = require('../../src/plugin_browser')
4
- const { PluginUtHelper } = require('../../utils/plugin_ut_helper')
1
+ import * as td from 'testdouble'
2
+ import assert from 'assert'
3
+ import PluginBrowser from '../../src/plugin_browser.mjs'
4
+ import { PluginUtHelper } from '../../utils/plugin_ut_helper.js'
5
5
 
6
6
  class StubAudio {
7
7
  contructor () {
@@ -1,5 +1,5 @@
1
- const PluginBrowser = require('../../src/plugin_browser')
2
- const { PluginUtHelper } = require('../../utils/plugin_ut_helper')
1
+ import PluginBrowser from '../../src/plugin_browser.mjs'
2
+ import { PluginUtHelper } from '../../utils/plugin_ut_helper.js'
3
3
 
4
4
  describe('plugin_browser_color', () => {
5
5
  const cu = new PluginUtHelper(PluginBrowser)
@@ -1,6 +1,6 @@
1
- const td = require('testdouble')
2
- const assert = require('assert').strict
3
- const PluginBrowser = require('../../src/plugin_browser')
1
+ import * as td from 'testdouble'
2
+ import PluginBrowser from '../../src/plugin_browser.mjs'
3
+ import assert from 'assert'
4
4
 
5
5
  describe('plugin_browser_dialog', () => {
6
6
  describe('言う', () => {
@@ -1,5 +1,5 @@
1
- const PluginBrowser = require('../../src/plugin_browser')
2
- const { PluginUtHelper } = require('../../utils/plugin_ut_helper')
1
+ import PluginBrowser from '../../src/plugin_browser.mjs'
2
+ import { PluginUtHelper } from '../../utils/plugin_ut_helper.js'
3
3
 
4
4
  describe('plugin_browser_html', () => {
5
5
  const cu = new PluginUtHelper(PluginBrowser)
@@ -1,5 +1,5 @@
1
- const PluginBrowser = require('../../src/plugin_browser')
2
- const { PluginUtHelper } = require('../../utils/plugin_ut_helper')
1
+ import PluginBrowser from '../../src/plugin_browser.mjs'
2
+ import { PluginUtHelper } from '../../utils/plugin_ut_helper.js'
3
3
 
4
4
  describe('plugin_browser_system', () => {
5
5
  const cu = new PluginUtHelper(PluginBrowser)
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const PluginCSV = require('../../src/plugin_csv')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import PluginCSV from '../../src/plugin_csv.mjs'
4
4
 
5
5
  describe('plugin_csv_test', () => {
6
6
  const nako = new NakoCompiler()
@@ -1,7 +1,7 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const {NakoRuntimeError} = require('../../src/nako_errors')
4
- const PluginDateTime = require('../../src/plugin_datetime')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import {NakoRuntimeError} from '../../src/nako_errors.mjs'
4
+ import PluginDateTime from '../../src/plugin_datetime.mjs'
5
5
 
6
6
  describe('plugin_datetime_test', () => {
7
7
  const nako = new NakoCompiler()
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const PluginKansuji = require('../../src/plugin_kansuji.js')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import PluginKansuji from '../../src/plugin_kansuji.mjs'
4
4
 
5
5
  describe('plugin_kansuji_test', () => {
6
6
  const nako = new NakoCompiler()
@@ -1,6 +1,6 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
3
- const PluginMarkup = require('../../src/plugin_markup')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
+ import PluginMarkup from '../../src/plugin_markup.mjs'
4
4
 
5
5
  describe('plugin_markup_test', () => {
6
6
  const nako = new NakoCompiler()
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('plugin_promise_test', () => {
5
5
  const nako = new NakoCompiler()
@@ -1,5 +1,5 @@
1
- const assert = require('assert')
2
- const NakoCompiler = require('../../src/nako3')
1
+ import assert from 'assert'
2
+ import { NakoCompiler } from '../../src/nako3.mjs'
3
3
 
4
4
  describe('plugin_system_test', () => {
5
5
  const nako = new NakoCompiler()