diff --git a/core/src/nako_gen.mts b/core/src/nako_gen.mts index c6138fe9..d8c9b362 100644 --- a/core/src/nako_gen.mts +++ b/core/src/nako_gen.mts @@ -1856,11 +1856,7 @@ export class NakoGen { let code = '/*[convLetProp]*/' // 変数が存在しないとき if (res === null) { - throw NakoSyntaxError.fromNode('変数が見当たりません。', node) - } - // ネームスペースを削除 - if (prop.indexOf('__') >= 0) { - prop = prop.split('__')[1] + throw NakoSyntaxError.fromNode(`変数『${name}』が見当たりません。`, node) } // プロパティへの代入式を作る const propVar = `${res.js}['${prop}']` diff --git a/core/src/nako_parser3.mts b/core/src/nako_parser3.mts index 2fab48a6..98516338 100644 --- a/core/src/nako_parser3.mts +++ b/core/src/nako_parser3.mts @@ -1556,36 +1556,24 @@ export class NakoParser extends NakoParserBase { throw NakoSyntaxError.fromNode(`${this.nodeToStr(word, { depth: 1 }, false)}への代入文で計算式に以下の書き間違いがあります。\n${err.message}`, map) } } - // プロパティ代入文 - if (this.check2(['word', '$', 'word', 'eq'])) { + // プロパティ代入文 (#1793) + if (this.check2(['word', '$', 'word', 'eq']) || this.check2(['word', '$', 'string', 'eq'])) { const word = this.peek() - let threw = false - try { - if (this.accept(['word', '$', 'word', 'eq', this.yCalc])) { - const nameToken = this.getVarName(this.y[0]) - const propToken = this.getVarName(this.y[2]) - const valueToken = this.y[4] - return { - type: 'let_prop', - name: (nameToken as AstStrValue).value, - index: [propToken], - blocks: [valueToken], - josi: '', - ...map, - end: this.peekSourceMap() - } as AstLet - } else { - threw = true - this.logger.debug(`${this.nodeToStr(word, { depth: 1 }, true)}への代入文で計算式に書き間違いがあります。`, word) - throw NakoSyntaxError.fromNode(`${this.nodeToStr(word, { depth: 1 }, false)}への代入文で計算式に書き間違いがあります。`, map) - } - } catch (err: any) { - if (threw) { - throw err - } - this.logger.debug(`${this.nodeToStr(word, { depth: 1 }, true)}への代入文で計算式に以下の書き間違いがあります。\n${err.message}`, word) - throw NakoSyntaxError.fromNode(`${this.nodeToStr(word, { depth: 1 }, false)}への代入文で計算式に以下の書き間違いがあります。\n${err.message}`, map) + if (this.accept(['word', '$', 'word', 'eq', this.yCalc]) || this.accept(['word', '$', 'string', 'eq', this.yCalc])) { + const nameToken = this.getVarName(this.y[0]) + const propToken = this.y[2] + const valueToken = this.y[4] + return { + type: 'let_prop', + name: (nameToken as AstStrValue).value, + index: [propToken], + blocks: [valueToken], + josi: '', + ...map, + end: this.peekSourceMap() + } as AstLet } + throw NakoSyntaxError.fromNode(`${this.nodeToStr(word, { depth: 1 }, false)}への代入文の計算式に書き間違いがあります。`, map) } // let_array ? @@ -2324,7 +2312,7 @@ export class NakoParser extends NakoParserBase { } // word$prop - if (word.josi === '' && this.check2(['$', 'word'])) { + if (word.josi === '' && (this.check2(['$', 'word']) || this.check2(['$', 'string']))) { this.get() // skip '$' const prop = this.get() as Token return { diff --git a/core/test/basic_test.mjs b/core/test/basic_test.mjs index c0438149..e00706c0 100644 --- a/core/test/basic_test.mjs +++ b/core/test/basic_test.mjs @@ -390,4 +390,8 @@ describe('basic', async () => { 'A={"幅": 3, "__setProp": F_SET, "__getProp": F_GET};\n' + 'A$幅=5; A$幅を表示', '50') }) + it('オブジェクトを手軽に設定する-文字列 (#1793)', async () => { + await cmp('A={"幅":30};A$"幅"=50;A$"幅"を表示', '50') + await cmp('A={"高":30};A$"高"=50;A$"高"を表示', '50') // 送り仮名の省略 + }) })