diff --git a/bundle_esbuild.js b/bundle_esbuild.js index 1fad6edb..976e3818 100644 --- a/bundle_esbuild.js +++ b/bundle_esbuild.js @@ -28,6 +28,7 @@ const files = [ ] const outdir = path.join(__dirname, 'release') const watch = process.argv.includes('--watch') +const filesFullpath = files.map((f) => path.join(__dirname, f)) // create outdir if (!fs.existsSync(outdir)) { @@ -35,15 +36,19 @@ if (!fs.existsSync(outdir)) { console.log(`[esbuild] created ${outdir}`) } // build options -const options = { - entryPoints: files, - bundle: true, - outdir, - minify: true, - sourcemap: true, -} if (!watch) { - await esbuild.build(options) + for (const f of files) { + const outfile = path.join(outdir, path.basename(f).replace(/\.(mjs|mts|jsx)$/, '.js')) + const options = { + entryPoints: [f], + bundle: true, + outfile, + minify: true, + sourcemap: true, + } + console.log('[esbuild] build start', options) + await esbuild.build(options) + } // 例外的なコピー const src = path.join(outdir, 'edit_main.js') if (fs.existsSync(src)) { @@ -51,6 +56,14 @@ if (!watch) { fs.copyFileSync(path.join(outdir, 'version_main.js'), path.join(outdir, 'version.js')) } } else { + // TODO: watch がうまく動かない + const options = { + entryPoints: filesFullpath, + bundle: true, + outdir, + minify: true, + sourcemap: true, + } const ctx = await esbuild.context(options) await ctx.watch() } diff --git a/core/package.json b/core/package.json index 546962c5..8ead4b8f 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "nadesiko3core", - "version": "3.6.13", + "version": "3.6.14", "description": "Japanese Programming Language Nadesiko v3 core", "main": "index.mjs", "type": "module", @@ -47,7 +47,7 @@ "@typescript-eslint/eslint-plugin": "^5.60.0", "eslint-config-standard-with-typescript": "^35.0.0", "mocha": "^10.2.0", - "typescript": "^5.1.3" + "typescript": "^5.5.3" }, "dependencies": { "cross-env": "^7.0.3" diff --git a/core/src/nako_core_version.mts b/core/src/nako_core_version.mts index a97dff31..0e696cfd 100644 --- a/core/src/nako_core_version.mts +++ b/core/src/nako_core_version.mts @@ -11,9 +11,9 @@ export interface NakoCoreVersion { } // 実際のバージョン定義 (自動生成されるので以下を編集しない) const coreVersion: NakoCoreVersion = { - version: '3.6.9', + version: '3.6.14', major: 3, minor: 6, - patch: 9 + patch: 14 } export default coreVersion diff --git a/core/src/nako_gen.mts b/core/src/nako_gen.mts index 759637c2..61f24e96 100644 --- a/core/src/nako_gen.mts +++ b/core/src/nako_gen.mts @@ -268,14 +268,21 @@ export class NakoGen { */ varname_set (name: string, jsvalue: string): string { if (this.varslistSet.length === 3) { - // グローバル - return `__self.__varslist[${2}].set(${JSON.stringify(name)}, (${jsvalue}))` + return `__self.__varslist[2].set(${JSON.stringify(name)}, (${jsvalue}))` } else { - // ローカル return `__self.__vars.set(${JSON.stringify(name)}, (${jsvalue}))` } } + /** + * ローカル変数の設定用JavaScriptコードを生成する。 + * @param {string} name + * @param {string} jsvalue + */ + varname_set_sys(name: string, jsvalue: string): string { + return `__self.__setSysVar(${JSON.stringify(name)}, (${jsvalue}))` + } + /** * @param {string} name * @returns {string} @@ -1145,20 +1152,22 @@ export class NakoGen { const loopKeyVar = `$nako_i${id}` const loopValueVar = `$nako_foreach_value${id}` const loopDataVar = `$nako_foreach_data${id}` + // 「対象」「対象キー」を取得 --- blockより早く変数を定義する必要がある - let valueVar = '対象' + let taisyoPrefex = this.varname_set_sys('対象', loopValueVar); if (node.name) { // 対象変数がある場合、対象は設定されない - valueVar = '' + (node.name as Ast).value + const valueVar = '' + (node.name as Ast).value + this.varsSet.names.add(valueVar) + taisyoPrefex = this.varname_set(valueVar, loopValueVar) } - this.varsSet.names.add(valueVar) const keyVar = '対象キー' - this.varsSet.names.add(keyVar) - const keySetter = this.varname_set(keyVar, loopKeyVar) + const keySetter = this.varname_set_sys(keyVar, loopKeyVar) // 「それ」(対象のエイリアス)の設定 let sorePrefex = '' if (this.speedMode.invalidSore === 0) { sorePrefex = this.varname_set('それ', loopValueVar) } + // 反復するデータを取得 let targetData = '' if (node.target === null) { @@ -1189,7 +1198,7 @@ export class NakoGen { ' // 対象の設定\n' + ` let ${loopValueVar} = $nako_foreach_data${id}[${loopKeyVar}]\n` + ` ${sorePrefex};\n` + - ` ${this.varname_set(valueVar, loopValueVar)}\n` + + ` ${taisyoPrefex};\n` + ' // [convForeach::block]\n' + ` ${block}\n` + ' // [/convForeach::block]\n' + diff --git a/core/test/flow_test.mjs b/core/test/flow_test.mjs index 60afe9d5..075023aa 100644 --- a/core/test/flow_test.mjs +++ b/core/test/flow_test.mjs @@ -452,4 +452,7 @@ describe('flow_test', async () => { await cmp('N=「」;1から3の範囲を繰り返す\nN=N&それ;\nここまで;Nを表示。', '123') await cmp('N=「」;0…9を繰り返す\nN=N&それ;\nここまで;Nを表示。', '0123456789') }) + it('対象がローカル変数になっていた問題 #1723', async () => { + await cmp('関数 Fとは; [1]を反復; ここまで。ここまで;対象=50;F;対象を表示。', '1') + }) }) diff --git a/core/tsconfig.json b/core/tsconfig.json index 18304619..c145a498 100644 --- a/core/tsconfig.json +++ b/core/tsconfig.json @@ -1,13 +1,6 @@ { - "ts-node": { - "esm": true, - "require": [ - "tsconfig-paths/register" - ] - }, "compilerOptions": { /* Visit https://aka.ms/tsconfig.json to read more about this file */ - /* Projects */ // "incremental": true, /* Enable incremental compilation */ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ @@ -17,8 +10,8 @@ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ /* Language and Environment */ - "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + "target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": ["dom"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ // "jsx": "preserve", /* Specify what JSX code is generated. */ // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ @@ -30,14 +23,15 @@ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ /* Modules */ - "module": "NodeNext", /* Specify what module code is generated. */ + "module": "ESNext", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */ - "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ - // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "paths": { + }, // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ - "typeRoots": ["src/@types", "node_modules/@types"], /* Specify multiple folders that act like `./node_modules/@types`. */ - "types": ["node"], /* Specify type package names to be included without being referenced in a source file. */ + "typeRoots": ["src/@types","node_modules/@types",], /* Specify multiple folders that act like `./node_modules/@types`. */ + "types": ["node", "mocha"], /* Specify type package names to be included without being referenced in a source file. */ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "resolveJsonModule": true, /* Enable importing .json files */ // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ @@ -102,7 +96,16 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + /* + "allowImportingTsExtensions": true, + "noEmit": true + */ }, - "exclude": ["deno/*"] + /* "extends": "./core/tsconfig.json", */ + "exclude": ["core/deno/*", "deno/*", "utils/*", "core/sample/*"], + "include": ["core/*", "core/src/*", "src/*"], + "ts-node": { + "esm": true + } }