LongTengDao / j-toml

A Node.js implementation of TOML written by LongTengDao. Belong to "Plan J"./龙腾道为汤小明语写的 Node.js 实现。从属于“简计划”。
https://npmjs.com/package/@ltd/j-toml
GNU Lesser General Public License v3.0
55 stars 6 forks source link

SyntaxError: Bad bare key at line 1 #5

Closed hustcer closed 3 years ago

hustcer commented 3 years ago

redevelopFile content:

template = 'RN_B2C'
checkout = 'support/seldon2'

using TOML.parse(redevelopFile, 1.0, '\r\n') error:

(node:84798) UnhandledPromiseRejectionWarning: SyntaxError: Bad bare key at line 1: /Users/hustcer/github/terminus/gaia-mobile/redevelop.b2c.toml
    at getKeys (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:696:101)
    at KEY_VALUE_PAIR_exec_groups (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:728:23)
    at assign (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1818:46)
    at Root (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1906:24)
    at Module.parse (/Users/hustcer/github/terminus/mall-base/node_modules/@ltd/j-toml/index.js:1952:23)
    at module.exports (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/src/commands/redevelop.js:293:44)
    at Command.<anonymous> (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/src/cli/index.js:107:5)
    at Command.listener [as _actionHandler] (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:466:17)
    at /Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:1170:65
    at Command._chainOrCall (/Users/hustcer/github/terminus/mall-base/packages/mall-tools/node_modules/commander/lib/command.js:1088:12)
LongTengDao commented 3 years ago

@hustcer I guess the file content is string type starting with BOM (U+FEFF), which is not a valid character in TOML. You can trim that before parsing, or directly pass in the Buffer type, because BOM belongs to UTF, and will be auto trimmed by the parser when toString.

LongTengDao commented 3 years ago

※ From v1.18.0, this error would be more friendly.