Skip to content

Commit e21013a

Browse files
committed
npm run all
1 parent b366782 commit e21013a

File tree

1 file changed

+75
-59
lines changed

1 file changed

+75
-59
lines changed

dist/index.js

Lines changed: 75 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5784,14 +5784,15 @@ function makeParserClass (Parser) {
57845784
let target = this.ctx
57855785
let finalKey = kv.key.pop()
57865786
for (let kw of kv.key) {
5787-
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) {
5787+
if (hasKey(target, kw) && !isTable(target[kw])) {
57885788
throw this.error(new TomlError("Can't redefine existing key"))
57895789
}
57905790
target = target[kw] = target[kw] || Table()
57915791
}
57925792
if (hasKey(target, finalKey)) {
57935793
throw this.error(new TomlError("Can't redefine existing key"))
57945794
}
5795+
target[_declared] = true
57955796
// unbox our numbers
57965797
if (isInteger(kv.value) || isFloat(kv.value)) {
57975798
target[finalKey] = kv.value.valueOf()
@@ -5849,6 +5850,8 @@ function makeParserClass (Parser) {
58495850
do {
58505851
if (this.char === Parser.END || this.char === CTRL_J) {
58515852
return this.return()
5853+
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
5854+
throw this.errorControlCharIn('comments')
58525855
}
58535856
} while (this.nextChar())
58545857
}
@@ -6062,7 +6065,7 @@ function makeParserClass (Parser) {
60626065
} else if (this.atEndOfLine()) {
60636066
throw this.error(new TomlError('Unterminated string'))
60646067
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
6065-
throw this.errorControlCharInString()
6068+
throw this.errorControlCharIn('strings')
60666069
} else {
60676070
this.consume()
60686071
}
@@ -6091,7 +6094,7 @@ function makeParserClass (Parser) {
60916094
} else if (this.char === Parser.END) {
60926095
throw this.error(new TomlError('Unterminated multi-line string'))
60936096
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
6094-
throw this.errorControlCharInString()
6097+
throw this.errorControlCharIn('strings')
60956098
} else {
60966099
this.consume()
60976100
}
@@ -6107,12 +6110,28 @@ function makeParserClass (Parser) {
61076110
}
61086111
parseLiteralMultiEnd2 () {
61096112
if (this.char === CHAR_APOS) {
6110-
return this.return()
6113+
return this.next(this.parseLiteralMultiEnd3)
61116114
} else {
61126115
this.state.buf += "''"
61136116
return this.goto(this.parseLiteralMultiStringContent)
61146117
}
61156118
}
6119+
parseLiteralMultiEnd3 () {
6120+
if (this.char === CHAR_APOS) {
6121+
this.state.buf += "'"
6122+
return this.next(this.parseLiteralMultiEnd4)
6123+
} else {
6124+
return this.returnNow()
6125+
}
6126+
}
6127+
parseLiteralMultiEnd4 () {
6128+
if (this.char === CHAR_APOS) {
6129+
this.state.buf += "'"
6130+
return this.return()
6131+
} else {
6132+
return this.returnNow()
6133+
}
6134+
}
61166135

61176136
/* STRINGS double quoted */
61186137
parseDoubleString () {
@@ -6131,7 +6150,7 @@ function makeParserClass (Parser) {
61316150
} else if (this.atEndOfLine()) {
61326151
throw this.error(new TomlError('Unterminated string'))
61336152
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I)) {
6134-
throw this.errorControlCharInString()
6153+
throw this.errorControlCharIn('strings')
61356154
} else {
61366155
this.consume()
61376156
}
@@ -6166,20 +6185,20 @@ function makeParserClass (Parser) {
61666185
} else if (this.char === Parser.END) {
61676186
throw this.error(new TomlError('Unterminated multi-line string'))
61686187
} else if (this.char === CHAR_DEL || (this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M)) {
6169-
throw this.errorControlCharInString()
6188+
throw this.errorControlCharIn('strings')
61706189
} else {
61716190
this.consume()
61726191
}
61736192
} while (this.nextChar())
61746193
}
6175-
errorControlCharInString () {
6194+
errorControlCharIn (type) {
61766195
let displayCode = '\\u00'
61776196
if (this.char < 16) {
61786197
displayCode += '0'
61796198
}
61806199
displayCode += this.char.toString(16)
61816200

6182-
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`))
6201+
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in ${type}, use ${displayCode} instead`))
61836202
}
61846203
recordMultiEscapeReplacement (replacement) {
61856204
this.state.buf += replacement
@@ -6195,12 +6214,28 @@ function makeParserClass (Parser) {
61956214
}
61966215
parseMultiEnd2 () {
61976216
if (this.char === CHAR_QUOT) {
6198-
return this.return()
6217+
return this.next(this.parseMultiEnd3)
61996218
} else {
62006219
this.state.buf += '""'
62016220
return this.goto(this.parseMultiStringContent)
62026221
}
62036222
}
6223+
parseMultiEnd3 () {
6224+
if (this.char === CHAR_QUOT) {
6225+
this.state.buf += '"'
6226+
return this.next(this.parseMultiEnd4)
6227+
} else {
6228+
return this.returnNow()
6229+
}
6230+
}
6231+
parseMultiEnd4 () {
6232+
if (this.char === CHAR_QUOT) {
6233+
this.state.buf += '"'
6234+
return this.return()
6235+
} else {
6236+
return this.returnNow()
6237+
}
6238+
}
62046239
parseMultiEscape () {
62056240
if (this.char === CTRL_M || this.char === CTRL_J) {
62066241
return this.next(this.parseMultiTrim)
@@ -6762,13 +6797,7 @@ function makeParserClass (Parser) {
67626797
}
67636798
}
67646799
recordInlineListValue (value) {
6765-
if (this.state.resultArr) {
6766-
const listType = this.state.resultArr[_contentType]
6767-
const valueType = tomlType(value)
6768-
if (listType !== valueType) {
6769-
throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`))
6770-
}
6771-
} else {
6800+
if (!this.state.resultArr) {
67726801
this.state.resultArr = InlineList(tomlType(value))
67736802
}
67746803
if (isFloat(value) || isInteger(value)) {
@@ -6831,13 +6860,26 @@ function makeParserClass (Parser) {
68316860
} else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
68326861
throw this.error(new TomlError('Unterminated inline array'))
68336862
} else if (this.char === CHAR_COMMA) {
6834-
return this.next(this.parseInlineTable)
6863+
return this.next(this.parseInlineTablePostComma)
68356864
} else if (this.char === CHAR_RCUB) {
68366865
return this.goto(this.parseInlineTable)
68376866
} else {
68386867
throw this.error(new TomlError('Invalid character, expected whitespace, comma (,) or close bracket (])'))
68396868
}
68406869
}
6870+
parseInlineTablePostComma () {
6871+
if (this.char === CHAR_SP || this.char === CTRL_I) {
6872+
return null
6873+
} else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) {
6874+
throw this.error(new TomlError('Unterminated inline array'))
6875+
} else if (this.char === CHAR_COMMA) {
6876+
throw this.error(new TomlError('Empty elements in inline tables are not permitted'))
6877+
} else if (this.char === CHAR_RCUB) {
6878+
throw this.error(new TomlError('Trailing commas in inline tables are not permitted'))
6879+
} else {
6880+
return this.goto(this.parseInlineTable)
6881+
}
6882+
}
68416883
}
68426884
return TOMLParser
68436885
}
@@ -7075,10 +7117,6 @@ function typeError (type) {
70757117
return new Error('Can only stringify objects, not ' + type)
70767118
}
70777119

7078-
function arrayOneTypeError () {
7079-
return new Error("Array values can't have mixed types")
7080-
}
7081-
70827120
function getInlineKeys (obj) {
70837121
return Object.keys(obj).filter(key => isInline(obj[key]))
70847122
}
@@ -7100,20 +7138,20 @@ function toJSON (obj) {
71007138

71017139
function stringifyObject (prefix, indent, obj) {
71027140
obj = toJSON(obj)
7103-
var inlineKeys
7104-
var complexKeys
7141+
let inlineKeys
7142+
let complexKeys
71057143
inlineKeys = getInlineKeys(obj)
71067144
complexKeys = getComplexKeys(obj)
7107-
var result = []
7108-
var inlineIndent = indent || ''
7145+
const result = []
7146+
const inlineIndent = indent || ''
71097147
inlineKeys.forEach(key => {
71107148
var type = tomlType(obj[key])
71117149
if (type !== 'undefined' && type !== 'null') {
71127150
result.push(inlineIndent + stringifyKey(key) + ' = ' + stringifyAnyInline(obj[key], true))
71137151
}
71147152
})
71157153
if (result.length > 0) result.push('')
7116-
var complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
7154+
const complexIndent = prefix && inlineKeys.length > 0 ? indent + ' ' : ''
71177155
complexKeys.forEach(key => {
71187156
result.push(stringifyComplex(prefix, complexIndent, key, obj[key]))
71197157
})
@@ -7165,7 +7203,7 @@ function tomlType (value) {
71657203
}
71667204

71677205
function stringifyKey (key) {
7168-
var keyStr = String(key)
7206+
const keyStr = String(key)
71697207
if (/^[-A-Za-z0-9_]+$/.test(keyStr)) {
71707208
return keyStr
71717209
} else {
@@ -7261,9 +7299,7 @@ function stringifyFloat (value) {
72617299
} else if (Object.is(value, -0)) {
72627300
return '-0.0'
72637301
}
7264-
var chunks = String(value).split('.')
7265-
var int = chunks[0]
7266-
var dec = chunks[1] || 0
7302+
const [int, dec] = String(value).split('.')
72677303
return stringifyInteger(int) + '.' + dec
72687304
}
72697305

@@ -7275,29 +7311,10 @@ function stringifyDatetime (value) {
72757311
return value.toISOString()
72767312
}
72777313

7278-
function isNumber (type) {
7279-
return type === 'float' || type === 'integer'
7280-
}
7281-
function arrayType (values) {
7282-
var contentType = tomlType(values[0])
7283-
if (values.every(_ => tomlType(_) === contentType)) return contentType
7284-
// mixed integer/float, emit as floats
7285-
if (values.every(_ => isNumber(tomlType(_)))) return 'float'
7286-
return 'mixed'
7287-
}
7288-
function validateArray (values) {
7289-
const type = arrayType(values)
7290-
if (type === 'mixed') {
7291-
throw arrayOneTypeError()
7292-
}
7293-
return type
7294-
}
7295-
72967314
function stringifyInlineArray (values) {
72977315
values = toJSON(values)
7298-
const type = validateArray(values)
7299-
var result = '['
7300-
var stringified = values.map(_ => stringifyInline(_, type))
7316+
let result = '['
7317+
const stringified = values.map(_ => stringifyInline(_))
73017318
if (stringified.join(', ').length > 60 || /\n/.test(stringified)) {
73027319
result += '\n ' + stringified.join(',\n ') + '\n'
73037320
} else {
@@ -7308,15 +7325,15 @@ function stringifyInlineArray (values) {
73087325

73097326
function stringifyInlineTable (value) {
73107327
value = toJSON(value)
7311-
var result = []
7328+
const result = []
73127329
Object.keys(value).forEach(key => {
73137330
result.push(stringifyKey(key) + ' = ' + stringifyAnyInline(value[key], false))
73147331
})
73157332
return '{ ' + result.join(', ') + (result.length > 0 ? ' ' : '') + '}'
73167333
}
73177334

73187335
function stringifyComplex (prefix, indent, key, value) {
7319-
var valueType = tomlType(value)
7336+
const valueType = tomlType(value)
73207337
/* istanbul ignore else */
73217338
if (valueType === 'array') {
73227339
return stringifyArrayOfTables(prefix, indent, key, value)
@@ -7329,12 +7346,11 @@ function stringifyComplex (prefix, indent, key, value) {
73297346

73307347
function stringifyArrayOfTables (prefix, indent, key, values) {
73317348
values = toJSON(values)
7332-
validateArray(values)
7333-
var firstValueType = tomlType(values[0])
7349+
const firstValueType = tomlType(values[0])
73347350
/* istanbul ignore if */
73357351
if (firstValueType !== 'table') throw typeError(firstValueType)
7336-
var fullKey = prefix + stringifyKey(key)
7337-
var result = ''
7352+
const fullKey = prefix + stringifyKey(key)
7353+
let result = ''
73387354
values.forEach(table => {
73397355
if (result.length > 0) result += '\n'
73407356
result += indent + '[[' + fullKey + ']]\n'
@@ -7344,8 +7360,8 @@ function stringifyArrayOfTables (prefix, indent, key, values) {
73447360
}
73457361

73467362
function stringifyComplexTable (prefix, indent, key, value) {
7347-
var fullKey = prefix + stringifyKey(key)
7348-
var result = ''
7363+
const fullKey = prefix + stringifyKey(key)
7364+
let result = ''
73497365
if (getInlineKeys(value).length > 0) {
73507366
result += indent + '[' + fullKey + ']\n'
73517367
}

0 commit comments

Comments
 (0)