@parcel/utils 2.0.0-nightly.1439 → 2.0.0-nightly.1441
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.
- package/lib/index.js +153 -153
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1854,19 +1854,19 @@ parcelRegister("2nj4a", function(module, exports) {
|
|
|
1854
1854
|
/* eslint-disable no-new-wrappers, no-eval, camelcase, operator-linebreak */ module.exports = makeParserClass((parcelRequire("ibqqh")));
|
|
1855
1855
|
module.exports.makeParserClass = makeParserClass;
|
|
1856
1856
|
class TomlError extends Error {
|
|
1857
|
-
constructor(
|
|
1858
|
-
super(
|
|
1857
|
+
constructor(msg){
|
|
1858
|
+
super(msg);
|
|
1859
1859
|
this.name = "TomlError";
|
|
1860
1860
|
/* istanbul ignore next */ if (Error.captureStackTrace) Error.captureStackTrace(this, TomlError);
|
|
1861
1861
|
this.fromTOML = true;
|
|
1862
1862
|
this.wrapped = null;
|
|
1863
1863
|
}
|
|
1864
1864
|
}
|
|
1865
|
-
TomlError.wrap = (
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
return
|
|
1865
|
+
TomlError.wrap = (err)=>{
|
|
1866
|
+
const terr = new TomlError(err.message);
|
|
1867
|
+
terr.code = err.code;
|
|
1868
|
+
terr.wrapped = err;
|
|
1869
|
+
return terr;
|
|
1870
1870
|
};
|
|
1871
1871
|
module.exports.TomlError = TomlError;
|
|
1872
1872
|
|
|
@@ -1934,23 +1934,23 @@ const escapes = {
|
|
|
1934
1934
|
[CHAR_QUOT]: '"',
|
|
1935
1935
|
[CHAR_BSOL]: "\\"
|
|
1936
1936
|
};
|
|
1937
|
-
function isDigit(
|
|
1938
|
-
return
|
|
1937
|
+
function isDigit(cp) {
|
|
1938
|
+
return cp >= CHAR_0 && cp <= CHAR_9;
|
|
1939
1939
|
}
|
|
1940
|
-
function isHexit(
|
|
1941
|
-
return
|
|
1940
|
+
function isHexit(cp) {
|
|
1941
|
+
return cp >= CHAR_A && cp <= CHAR_F || cp >= CHAR_a && cp <= CHAR_f || cp >= CHAR_0 && cp <= CHAR_9;
|
|
1942
1942
|
}
|
|
1943
|
-
function isBit(
|
|
1944
|
-
return
|
|
1943
|
+
function isBit(cp) {
|
|
1944
|
+
return cp === CHAR_1 || cp === CHAR_0;
|
|
1945
1945
|
}
|
|
1946
|
-
function isOctit(
|
|
1947
|
-
return
|
|
1946
|
+
function isOctit(cp) {
|
|
1947
|
+
return cp >= CHAR_0 && cp <= CHAR_7;
|
|
1948
1948
|
}
|
|
1949
|
-
function isAlphaNumQuoteHyphen(
|
|
1950
|
-
return
|
|
1949
|
+
function isAlphaNumQuoteHyphen(cp) {
|
|
1950
|
+
return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_APOS || cp === CHAR_QUOT || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
|
|
1951
1951
|
}
|
|
1952
|
-
function isAlphaNumHyphen(
|
|
1953
|
-
return
|
|
1952
|
+
function isAlphaNumHyphen(cp) {
|
|
1953
|
+
return cp >= CHAR_A && cp <= CHAR_Z || cp >= CHAR_a && cp <= CHAR_z || cp >= CHAR_0 && cp <= CHAR_9 || cp === CHAR_LOWBAR || cp === CHAR_HYPHEN;
|
|
1954
1954
|
}
|
|
1955
1955
|
const _type = Symbol("type");
|
|
1956
1956
|
const _declared = Symbol("declared");
|
|
@@ -1962,9 +1962,9 @@ const descriptor = {
|
|
|
1962
1962
|
writable: true,
|
|
1963
1963
|
value: undefined
|
|
1964
1964
|
};
|
|
1965
|
-
function hasKey(
|
|
1966
|
-
if (hasOwnProperty.call(
|
|
1967
|
-
if (
|
|
1965
|
+
function hasKey(obj, key) {
|
|
1966
|
+
if (hasOwnProperty.call(obj, key)) return true;
|
|
1967
|
+
if (key === "__proto__") defineProperty(obj, "__proto__", descriptor);
|
|
1968
1968
|
return false;
|
|
1969
1969
|
}
|
|
1970
1970
|
const INLINE_TABLE = Symbol("inline-table");
|
|
@@ -1975,9 +1975,9 @@ function InlineTable() {
|
|
|
1975
1975
|
}
|
|
1976
1976
|
});
|
|
1977
1977
|
}
|
|
1978
|
-
function isInlineTable(
|
|
1979
|
-
if (
|
|
1980
|
-
return
|
|
1978
|
+
function isInlineTable(obj) {
|
|
1979
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
1980
|
+
return obj[_type] === INLINE_TABLE;
|
|
1981
1981
|
}
|
|
1982
1982
|
const TABLE = Symbol("table");
|
|
1983
1983
|
function Table() {
|
|
@@ -1991,25 +1991,25 @@ function Table() {
|
|
|
1991
1991
|
}
|
|
1992
1992
|
});
|
|
1993
1993
|
}
|
|
1994
|
-
function isTable(
|
|
1995
|
-
if (
|
|
1996
|
-
return
|
|
1994
|
+
function isTable(obj) {
|
|
1995
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
1996
|
+
return obj[_type] === TABLE;
|
|
1997
1997
|
}
|
|
1998
1998
|
const _contentType = Symbol("content-type");
|
|
1999
1999
|
const INLINE_LIST = Symbol("inline-list");
|
|
2000
|
-
function InlineList(
|
|
2000
|
+
function InlineList(type) {
|
|
2001
2001
|
return Object.defineProperties([], {
|
|
2002
2002
|
[_type]: {
|
|
2003
2003
|
value: INLINE_LIST
|
|
2004
2004
|
},
|
|
2005
2005
|
[_contentType]: {
|
|
2006
|
-
value:
|
|
2006
|
+
value: type
|
|
2007
2007
|
}
|
|
2008
2008
|
});
|
|
2009
2009
|
}
|
|
2010
|
-
function isInlineList(
|
|
2011
|
-
if (
|
|
2012
|
-
return
|
|
2010
|
+
function isInlineList(obj) {
|
|
2011
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
2012
|
+
return obj[_type] === INLINE_LIST;
|
|
2013
2013
|
}
|
|
2014
2014
|
const LIST = Symbol("list");
|
|
2015
2015
|
function List() {
|
|
@@ -2019,9 +2019,9 @@ function List() {
|
|
|
2019
2019
|
}
|
|
2020
2020
|
});
|
|
2021
2021
|
}
|
|
2022
|
-
function isList(
|
|
2023
|
-
if (
|
|
2024
|
-
return
|
|
2022
|
+
function isList(obj) {
|
|
2023
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
2024
|
+
return obj[_type] === LIST;
|
|
2025
2025
|
}
|
|
2026
2026
|
// in an eval, to let bundlers not slurp in a util proxy
|
|
2027
2027
|
let _custom;
|
|
@@ -2032,10 +2032,10 @@ try {
|
|
|
2032
2032
|
/* eval require not available in transpiled bundle */ }
|
|
2033
2033
|
/* istanbul ignore next */ const _inspect = _custom || "inspect";
|
|
2034
2034
|
class BoxedBigInt {
|
|
2035
|
-
constructor(
|
|
2035
|
+
constructor(value){
|
|
2036
2036
|
try {
|
|
2037
|
-
this.value = $parcel$global.BigInt.asIntN(64,
|
|
2038
|
-
} catch (
|
|
2037
|
+
this.value = $parcel$global.BigInt.asIntN(64, value);
|
|
2038
|
+
} catch (_) {
|
|
2039
2039
|
/* istanbul ignore next */ this.value = null;
|
|
2040
2040
|
}
|
|
2041
2041
|
Object.defineProperty(this, _type, {
|
|
@@ -2056,12 +2056,12 @@ class BoxedBigInt {
|
|
|
2056
2056
|
}
|
|
2057
2057
|
}
|
|
2058
2058
|
const INTEGER = Symbol("integer");
|
|
2059
|
-
function Integer(
|
|
2060
|
-
let
|
|
2059
|
+
function Integer(value) {
|
|
2060
|
+
let num = Number(value);
|
|
2061
2061
|
// -0 is a float thing, not an int thing
|
|
2062
|
-
if (Object.is(
|
|
2063
|
-
/* istanbul ignore else */ if ($parcel$global.BigInt && !Number.isSafeInteger(
|
|
2064
|
-
else /* istanbul ignore next */ return Object.defineProperties(new Number(
|
|
2062
|
+
if (Object.is(num, -0)) num = 0;
|
|
2063
|
+
/* istanbul ignore else */ if ($parcel$global.BigInt && !Number.isSafeInteger(num)) return new BoxedBigInt(value);
|
|
2064
|
+
else /* istanbul ignore next */ return Object.defineProperties(new Number(num), {
|
|
2065
2065
|
isNaN: {
|
|
2066
2066
|
value: function() {
|
|
2067
2067
|
return isNaN(this);
|
|
@@ -2071,35 +2071,35 @@ function Integer(value11) {
|
|
|
2071
2071
|
value: INTEGER
|
|
2072
2072
|
},
|
|
2073
2073
|
[_inspect]: {
|
|
2074
|
-
value: ()=>`[Integer: ${
|
|
2074
|
+
value: ()=>`[Integer: ${value}]`
|
|
2075
2075
|
}
|
|
2076
2076
|
});
|
|
2077
2077
|
}
|
|
2078
|
-
function isInteger(
|
|
2079
|
-
if (
|
|
2080
|
-
return
|
|
2078
|
+
function isInteger(obj) {
|
|
2079
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
2080
|
+
return obj[_type] === INTEGER;
|
|
2081
2081
|
}
|
|
2082
2082
|
const FLOAT = Symbol("float");
|
|
2083
|
-
function Float(
|
|
2084
|
-
/* istanbul ignore next */ return Object.defineProperties(new Number(
|
|
2083
|
+
function Float(value) {
|
|
2084
|
+
/* istanbul ignore next */ return Object.defineProperties(new Number(value), {
|
|
2085
2085
|
[_type]: {
|
|
2086
2086
|
value: FLOAT
|
|
2087
2087
|
},
|
|
2088
2088
|
[_inspect]: {
|
|
2089
|
-
value: ()=>`[Float: ${
|
|
2089
|
+
value: ()=>`[Float: ${value}]`
|
|
2090
2090
|
}
|
|
2091
2091
|
});
|
|
2092
2092
|
}
|
|
2093
|
-
function isFloat(
|
|
2094
|
-
if (
|
|
2095
|
-
return
|
|
2093
|
+
function isFloat(obj) {
|
|
2094
|
+
if (obj === null || typeof obj !== "object") return false;
|
|
2095
|
+
return obj[_type] === FLOAT;
|
|
2096
2096
|
}
|
|
2097
|
-
function tomlType(
|
|
2098
|
-
const
|
|
2099
|
-
if (
|
|
2100
|
-
/* istanbul ignore if */ if (
|
|
2101
|
-
if (
|
|
2102
|
-
/* istanbul ignore else */ if (_type in
|
|
2097
|
+
function tomlType(value) {
|
|
2098
|
+
const type = typeof value;
|
|
2099
|
+
if (type === "object") {
|
|
2100
|
+
/* istanbul ignore if */ if (value === null) return "null";
|
|
2101
|
+
if (value instanceof Date) return "datetime";
|
|
2102
|
+
/* istanbul ignore else */ if (_type in value) switch(value[_type]){
|
|
2103
2103
|
case INLINE_TABLE:
|
|
2104
2104
|
return "inline-table";
|
|
2105
2105
|
case INLINE_LIST:
|
|
@@ -2114,10 +2114,10 @@ function tomlType(value11) {
|
|
|
2114
2114
|
return "integer";
|
|
2115
2115
|
}
|
|
2116
2116
|
}
|
|
2117
|
-
return
|
|
2117
|
+
return type;
|
|
2118
2118
|
}
|
|
2119
|
-
function makeParserClass(
|
|
2120
|
-
class
|
|
2119
|
+
function makeParserClass(Parser) {
|
|
2120
|
+
class TOMLParser extends Parser {
|
|
2121
2121
|
constructor(){
|
|
2122
2122
|
super();
|
|
2123
2123
|
this.ctx = this.obj = Table();
|
|
@@ -2126,10 +2126,10 @@ function makeParserClass(Parser11) {
|
|
|
2126
2126
|
return this.char === CHAR_NUM || this.char === CTRL_I || this.char === CHAR_SP || this.atEndOfLine();
|
|
2127
2127
|
}
|
|
2128
2128
|
atEndOfLine() {
|
|
2129
|
-
return this.char ===
|
|
2129
|
+
return this.char === Parser.END || this.char === CTRL_J || this.char === CTRL_M;
|
|
2130
2130
|
}
|
|
2131
2131
|
parseStart() {
|
|
2132
|
-
if (this.char ===
|
|
2132
|
+
if (this.char === Parser.END) return null;
|
|
2133
2133
|
else if (this.char === CHAR_LSQB) return this.call(this.parseTableOrList);
|
|
2134
2134
|
else if (this.char === CHAR_NUM) return this.call(this.parseComment);
|
|
2135
2135
|
else if (this.char === CTRL_J || this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) return null;
|
|
@@ -2141,32 +2141,32 @@ function makeParserClass(Parser11) {
|
|
|
2141
2141
|
parseWhitespaceToEOL() {
|
|
2142
2142
|
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M) return null;
|
|
2143
2143
|
else if (this.char === CHAR_NUM) return this.goto(this.parseComment);
|
|
2144
|
-
else if (this.char ===
|
|
2144
|
+
else if (this.char === Parser.END || this.char === CTRL_J) return this.return();
|
|
2145
2145
|
else throw this.error(new TomlError("Unexpected character, expected only whitespace or comments till end of line"));
|
|
2146
2146
|
}
|
|
2147
2147
|
/* ASSIGNMENT: key = value */ parseAssignStatement() {
|
|
2148
2148
|
return this.callNow(this.parseAssign, this.recordAssignStatement);
|
|
2149
2149
|
}
|
|
2150
|
-
recordAssignStatement(
|
|
2151
|
-
let
|
|
2152
|
-
let
|
|
2153
|
-
for (let
|
|
2154
|
-
if (hasKey(
|
|
2155
|
-
|
|
2150
|
+
recordAssignStatement(kv) {
|
|
2151
|
+
let target = this.ctx;
|
|
2152
|
+
let finalKey = kv.key.pop();
|
|
2153
|
+
for (let kw of kv.key){
|
|
2154
|
+
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) throw this.error(new TomlError("Can't redefine existing key"));
|
|
2155
|
+
target = target[kw] = target[kw] || Table();
|
|
2156
2156
|
}
|
|
2157
|
-
if (hasKey(
|
|
2157
|
+
if (hasKey(target, finalKey)) throw this.error(new TomlError("Can't redefine existing key"));
|
|
2158
2158
|
// unbox our numbers
|
|
2159
|
-
if (isInteger(
|
|
2160
|
-
else
|
|
2159
|
+
if (isInteger(kv.value) || isFloat(kv.value)) target[finalKey] = kv.value.valueOf();
|
|
2160
|
+
else target[finalKey] = kv.value;
|
|
2161
2161
|
return this.goto(this.parseWhitespaceToEOL);
|
|
2162
2162
|
}
|
|
2163
2163
|
/* ASSSIGNMENT expression, key = value possibly inside an inline table */ parseAssign() {
|
|
2164
2164
|
return this.callNow(this.parseKeyword, this.recordAssignKeyword);
|
|
2165
2165
|
}
|
|
2166
|
-
recordAssignKeyword(
|
|
2167
|
-
if (this.state.resultTable) this.state.resultTable.push(
|
|
2166
|
+
recordAssignKeyword(key) {
|
|
2167
|
+
if (this.state.resultTable) this.state.resultTable.push(key);
|
|
2168
2168
|
else this.state.resultTable = [
|
|
2169
|
-
|
|
2169
|
+
key
|
|
2170
2170
|
];
|
|
2171
2171
|
return this.goto(this.parseAssignKeywordPreDot);
|
|
2172
2172
|
}
|
|
@@ -2185,15 +2185,15 @@ function makeParserClass(Parser11) {
|
|
|
2185
2185
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2186
2186
|
else return this.callNow(this.parseValue, this.recordAssignValue);
|
|
2187
2187
|
}
|
|
2188
|
-
recordAssignValue(
|
|
2188
|
+
recordAssignValue(value) {
|
|
2189
2189
|
return this.returnNow({
|
|
2190
2190
|
key: this.state.resultTable,
|
|
2191
|
-
value:
|
|
2191
|
+
value: value
|
|
2192
2192
|
});
|
|
2193
2193
|
}
|
|
2194
2194
|
/* COMMENTS: #...eol */ parseComment() {
|
|
2195
2195
|
do {
|
|
2196
|
-
if (this.char ===
|
|
2196
|
+
if (this.char === Parser.END || this.char === CTRL_J) return this.return();
|
|
2197
2197
|
}while (this.nextChar());
|
|
2198
2198
|
}
|
|
2199
2199
|
/* TABLES AND LISTS, [foo] and [[foo]] */ parseTableOrList() {
|
|
@@ -2208,19 +2208,19 @@ function makeParserClass(Parser11) {
|
|
|
2208
2208
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2209
2209
|
else return this.callNow(this.parseKeyword, this.parseTableMore);
|
|
2210
2210
|
}
|
|
2211
|
-
parseTableMore(
|
|
2211
|
+
parseTableMore(keyword) {
|
|
2212
2212
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2213
2213
|
else if (this.char === CHAR_RSQB) {
|
|
2214
|
-
if (hasKey(this.ctx,
|
|
2214
|
+
if (hasKey(this.ctx, keyword) && (!isTable(this.ctx[keyword]) || this.ctx[keyword][_declared])) throw this.error(new TomlError("Can't redefine existing key"));
|
|
2215
2215
|
else {
|
|
2216
|
-
this.ctx = this.ctx[
|
|
2216
|
+
this.ctx = this.ctx[keyword] = this.ctx[keyword] || Table();
|
|
2217
2217
|
this.ctx[_declared] = true;
|
|
2218
2218
|
}
|
|
2219
2219
|
return this.next(this.parseWhitespaceToEOL);
|
|
2220
2220
|
} else if (this.char === CHAR_PERIOD) {
|
|
2221
|
-
if (!hasKey(this.ctx,
|
|
2222
|
-
else if (isTable(this.ctx[
|
|
2223
|
-
else if (isList(this.ctx[
|
|
2221
|
+
if (!hasKey(this.ctx, keyword)) this.ctx = this.ctx[keyword] = Table();
|
|
2222
|
+
else if (isTable(this.ctx[keyword])) this.ctx = this.ctx[keyword];
|
|
2223
|
+
else if (isList(this.ctx[keyword])) this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
|
|
2224
2224
|
else throw this.error(new TomlError("Can't redefine existing key"));
|
|
2225
2225
|
return this.next(this.parseTableNext);
|
|
2226
2226
|
} else throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
|
|
@@ -2233,33 +2233,33 @@ function makeParserClass(Parser11) {
|
|
|
2233
2233
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2234
2234
|
else return this.callNow(this.parseKeyword, this.parseListMore);
|
|
2235
2235
|
}
|
|
2236
|
-
parseListMore(
|
|
2236
|
+
parseListMore(keyword) {
|
|
2237
2237
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2238
2238
|
else if (this.char === CHAR_RSQB) {
|
|
2239
|
-
if (!hasKey(this.ctx,
|
|
2240
|
-
if (isInlineList(this.ctx[
|
|
2241
|
-
else if (isList(this.ctx[
|
|
2242
|
-
const
|
|
2243
|
-
this.ctx[
|
|
2244
|
-
this.ctx =
|
|
2239
|
+
if (!hasKey(this.ctx, keyword)) this.ctx[keyword] = List();
|
|
2240
|
+
if (isInlineList(this.ctx[keyword])) throw this.error(new TomlError("Can't extend an inline array"));
|
|
2241
|
+
else if (isList(this.ctx[keyword])) {
|
|
2242
|
+
const next = Table();
|
|
2243
|
+
this.ctx[keyword].push(next);
|
|
2244
|
+
this.ctx = next;
|
|
2245
2245
|
} else throw this.error(new TomlError("Can't redefine an existing key"));
|
|
2246
2246
|
return this.next(this.parseListEnd);
|
|
2247
2247
|
} else if (this.char === CHAR_PERIOD) {
|
|
2248
|
-
if (!hasKey(this.ctx,
|
|
2249
|
-
else if (isInlineList(this.ctx[
|
|
2250
|
-
else if (isInlineTable(this.ctx[
|
|
2251
|
-
else if (isList(this.ctx[
|
|
2252
|
-
else if (isTable(this.ctx[
|
|
2248
|
+
if (!hasKey(this.ctx, keyword)) this.ctx = this.ctx[keyword] = Table();
|
|
2249
|
+
else if (isInlineList(this.ctx[keyword])) throw this.error(new TomlError("Can't extend an inline array"));
|
|
2250
|
+
else if (isInlineTable(this.ctx[keyword])) throw this.error(new TomlError("Can't extend an inline table"));
|
|
2251
|
+
else if (isList(this.ctx[keyword])) this.ctx = this.ctx[keyword][this.ctx[keyword].length - 1];
|
|
2252
|
+
else if (isTable(this.ctx[keyword])) this.ctx = this.ctx[keyword];
|
|
2253
2253
|
else throw this.error(new TomlError("Can't redefine an existing key"));
|
|
2254
2254
|
return this.next(this.parseListNext);
|
|
2255
2255
|
} else throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
|
|
2256
2256
|
}
|
|
2257
|
-
parseListEnd(
|
|
2257
|
+
parseListEnd(keyword) {
|
|
2258
2258
|
if (this.char === CHAR_RSQB) return this.next(this.parseWhitespaceToEOL);
|
|
2259
2259
|
else throw this.error(new TomlError("Unexpected character, expected whitespace, . or ]"));
|
|
2260
2260
|
}
|
|
2261
2261
|
/* VALUE string, number, boolean, inline list, inline object */ parseValue() {
|
|
2262
|
-
if (this.char ===
|
|
2262
|
+
if (this.char === Parser.END) throw this.error(new TomlError("Key without value"));
|
|
2263
2263
|
else if (this.char === CHAR_QUOT) return this.next(this.parseDoubleString);
|
|
2264
2264
|
if (this.char === CHAR_APOS) return this.next(this.parseSingleString);
|
|
2265
2265
|
else if (this.char === CHAR_HYPHEN || this.char === CHAR_PLUS) return this.goto(this.parseNumberSign);
|
|
@@ -2271,8 +2271,8 @@ function makeParserClass(Parser11) {
|
|
|
2271
2271
|
else if (this.char === CHAR_LCUB) return this.call(this.parseInlineTable, this.recordValue);
|
|
2272
2272
|
else throw this.error(new TomlError("Unexpected character, expecting string, number, datetime, boolean, inline array or inline table"));
|
|
2273
2273
|
}
|
|
2274
|
-
recordValue(
|
|
2275
|
-
return this.returnNow(
|
|
2274
|
+
recordValue(value) {
|
|
2275
|
+
return this.returnNow(value);
|
|
2276
2276
|
}
|
|
2277
2277
|
parseInf() {
|
|
2278
2278
|
if (this.char === CHAR_n) return this.next(this.parseInf2);
|
|
@@ -2299,7 +2299,7 @@ function makeParserClass(Parser11) {
|
|
|
2299
2299
|
}
|
|
2300
2300
|
/* KEYS: barewords */ parseBareKey() {
|
|
2301
2301
|
do {
|
|
2302
|
-
if (this.char ===
|
|
2302
|
+
if (this.char === Parser.END) throw this.error(new TomlError("Key ended without value"));
|
|
2303
2303
|
else if (isAlphaNumHyphen(this.char)) this.consume();
|
|
2304
2304
|
else if (this.state.buf.length === 0) throw this.error(new TomlError("Empty bare keys are not allowed"));
|
|
2305
2305
|
else return this.returnNow();
|
|
@@ -2329,7 +2329,7 @@ function makeParserClass(Parser11) {
|
|
|
2329
2329
|
parseLiteralMultiStringContent() {
|
|
2330
2330
|
do {
|
|
2331
2331
|
if (this.char === CHAR_APOS) return this.next(this.parseLiteralMultiEnd);
|
|
2332
|
-
else if (this.char ===
|
|
2332
|
+
else if (this.char === Parser.END) throw this.error(new TomlError("Unterminated multi-line string"));
|
|
2333
2333
|
else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) throw this.errorControlCharInString();
|
|
2334
2334
|
else this.consume();
|
|
2335
2335
|
}while (this.nextChar());
|
|
@@ -2361,8 +2361,8 @@ function makeParserClass(Parser11) {
|
|
|
2361
2361
|
else this.consume();
|
|
2362
2362
|
}while (this.nextChar());
|
|
2363
2363
|
}
|
|
2364
|
-
recordEscapeReplacement(
|
|
2365
|
-
this.state.buf +=
|
|
2364
|
+
recordEscapeReplacement(replacement) {
|
|
2365
|
+
this.state.buf += replacement;
|
|
2366
2366
|
return this.goto(this.parseBasicString);
|
|
2367
2367
|
}
|
|
2368
2368
|
parseMultiStringMaybe() {
|
|
@@ -2378,19 +2378,19 @@ function makeParserClass(Parser11) {
|
|
|
2378
2378
|
do {
|
|
2379
2379
|
if (this.char === CHAR_BSOL) return this.call(this.parseMultiEscape, this.recordMultiEscapeReplacement);
|
|
2380
2380
|
else if (this.char === CHAR_QUOT) return this.next(this.parseMultiEnd);
|
|
2381
|
-
else if (this.char ===
|
|
2381
|
+
else if (this.char === Parser.END) throw this.error(new TomlError("Unterminated multi-line string"));
|
|
2382
2382
|
else if (this.char === CHAR_DEL || this.char <= CTRL_CHAR_BOUNDARY && this.char !== CTRL_I && this.char !== CTRL_J && this.char !== CTRL_M) throw this.errorControlCharInString();
|
|
2383
2383
|
else this.consume();
|
|
2384
2384
|
}while (this.nextChar());
|
|
2385
2385
|
}
|
|
2386
2386
|
errorControlCharInString() {
|
|
2387
|
-
let
|
|
2388
|
-
if (this.char < 16)
|
|
2389
|
-
|
|
2390
|
-
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${
|
|
2387
|
+
let displayCode = "\\u00";
|
|
2388
|
+
if (this.char < 16) displayCode += "0";
|
|
2389
|
+
displayCode += this.char.toString(16);
|
|
2390
|
+
return this.error(new TomlError(`Control characters (codes < 0x1f and 0x7f) are not allowed in strings, use ${displayCode} instead`));
|
|
2391
2391
|
}
|
|
2392
|
-
recordMultiEscapeReplacement(
|
|
2393
|
-
this.state.buf +=
|
|
2392
|
+
recordMultiEscapeReplacement(replacement) {
|
|
2393
|
+
this.state.buf += replacement;
|
|
2394
2394
|
return this.goto(this.parseMultiStringContent);
|
|
2395
2395
|
}
|
|
2396
2396
|
parseMultiEnd() {
|
|
@@ -2428,13 +2428,13 @@ function makeParserClass(Parser11) {
|
|
|
2428
2428
|
else if (this.char === CHAR_U) return this.call(this.parseLargeUnicode, this.parseUnicodeReturn);
|
|
2429
2429
|
else throw this.error(new TomlError("Unknown escape character: " + this.char));
|
|
2430
2430
|
}
|
|
2431
|
-
parseUnicodeReturn(
|
|
2431
|
+
parseUnicodeReturn(char) {
|
|
2432
2432
|
try {
|
|
2433
|
-
const
|
|
2434
|
-
if (
|
|
2435
|
-
return this.returnNow(String.fromCodePoint(
|
|
2436
|
-
} catch (
|
|
2437
|
-
throw this.error(TomlError.wrap(
|
|
2433
|
+
const codePoint = parseInt(char, 16);
|
|
2434
|
+
if (codePoint >= SURROGATE_FIRST && codePoint <= SURROGATE_LAST) throw this.error(new TomlError("Invalid unicode, character in range 0xD800 - 0xDFFF is reserved"));
|
|
2435
|
+
return this.returnNow(String.fromCodePoint(codePoint));
|
|
2436
|
+
} catch (err) {
|
|
2437
|
+
throw this.error(TomlError.wrap(err));
|
|
2438
2438
|
}
|
|
2439
2439
|
}
|
|
2440
2440
|
parseSmallUnicode() {
|
|
@@ -2485,9 +2485,9 @@ function makeParserClass(Parser11) {
|
|
|
2485
2485
|
this.consume();
|
|
2486
2486
|
return this.call(this.parseNoUnder, this.parseNumberFloat);
|
|
2487
2487
|
} else {
|
|
2488
|
-
const
|
|
2489
|
-
/* istanbul ignore if */ if (
|
|
2490
|
-
else return this.returnNow(
|
|
2488
|
+
const result = Integer(this.state.buf);
|
|
2489
|
+
/* istanbul ignore if */ if (result.isNaN()) throw this.error(new TomlError("Invalid number"));
|
|
2490
|
+
else return this.returnNow(result);
|
|
2491
2491
|
}
|
|
2492
2492
|
}
|
|
2493
2493
|
parseNoUnder() {
|
|
@@ -2565,27 +2565,27 @@ function makeParserClass(Parser11) {
|
|
|
2565
2565
|
if (isHexit(this.char)) this.consume();
|
|
2566
2566
|
else if (this.char === CHAR_LOWBAR) return this.call(this.parseNoUnder);
|
|
2567
2567
|
else {
|
|
2568
|
-
const
|
|
2569
|
-
/* istanbul ignore if */ if (
|
|
2570
|
-
else return this.returnNow(
|
|
2568
|
+
const result = Integer(this.state.buf);
|
|
2569
|
+
/* istanbul ignore if */ if (result.isNaN()) throw this.error(new TomlError("Invalid number"));
|
|
2570
|
+
else return this.returnNow(result);
|
|
2571
2571
|
}
|
|
2572
2572
|
}
|
|
2573
2573
|
parseIntegerOct() {
|
|
2574
2574
|
if (isOctit(this.char)) this.consume();
|
|
2575
2575
|
else if (this.char === CHAR_LOWBAR) return this.call(this.parseNoUnder);
|
|
2576
2576
|
else {
|
|
2577
|
-
const
|
|
2578
|
-
/* istanbul ignore if */ if (
|
|
2579
|
-
else return this.returnNow(
|
|
2577
|
+
const result = Integer(this.state.buf);
|
|
2578
|
+
/* istanbul ignore if */ if (result.isNaN()) throw this.error(new TomlError("Invalid number"));
|
|
2579
|
+
else return this.returnNow(result);
|
|
2580
2580
|
}
|
|
2581
2581
|
}
|
|
2582
2582
|
parseIntegerBin() {
|
|
2583
2583
|
if (isBit(this.char)) this.consume();
|
|
2584
2584
|
else if (this.char === CHAR_LOWBAR) return this.call(this.parseNoUnder);
|
|
2585
2585
|
else {
|
|
2586
|
-
const
|
|
2587
|
-
/* istanbul ignore if */ if (
|
|
2588
|
-
else return this.returnNow(
|
|
2586
|
+
const result = Integer(this.state.buf);
|
|
2587
|
+
/* istanbul ignore if */ if (result.isNaN()) throw this.error(new TomlError("Invalid number"));
|
|
2588
|
+
else return this.returnNow(result);
|
|
2589
2589
|
}
|
|
2590
2590
|
}
|
|
2591
2591
|
/* DATETIME */ parseDateTime() {
|
|
@@ -2774,20 +2774,20 @@ function makeParserClass(Parser11) {
|
|
|
2774
2774
|
}
|
|
2775
2775
|
/* INLINE LISTS */ parseInlineList() {
|
|
2776
2776
|
if (this.char === CHAR_SP || this.char === CTRL_I || this.char === CTRL_M || this.char === CTRL_J) return null;
|
|
2777
|
-
else if (this.char ===
|
|
2777
|
+
else if (this.char === Parser.END) throw this.error(new TomlError("Unterminated inline array"));
|
|
2778
2778
|
else if (this.char === CHAR_NUM) return this.call(this.parseComment);
|
|
2779
2779
|
else if (this.char === CHAR_RSQB) return this.return(this.state.resultArr || InlineList());
|
|
2780
2780
|
else return this.callNow(this.parseValue, this.recordInlineListValue);
|
|
2781
2781
|
}
|
|
2782
|
-
recordInlineListValue(
|
|
2782
|
+
recordInlineListValue(value) {
|
|
2783
2783
|
if (this.state.resultArr) {
|
|
2784
|
-
const
|
|
2785
|
-
const
|
|
2786
|
-
if (
|
|
2787
|
-
} else this.state.resultArr = InlineList(tomlType(
|
|
2788
|
-
if (isFloat(
|
|
2789
|
-
this.state.resultArr.push(
|
|
2790
|
-
else this.state.resultArr.push(
|
|
2784
|
+
const listType = this.state.resultArr[_contentType];
|
|
2785
|
+
const valueType = tomlType(value);
|
|
2786
|
+
if (listType !== valueType) throw this.error(new TomlError(`Inline lists must be a single type, not a mix of ${listType} and ${valueType}`));
|
|
2787
|
+
} else this.state.resultArr = InlineList(tomlType(value));
|
|
2788
|
+
if (isFloat(value) || isInteger(value)) // unbox now that we've verified they're ok
|
|
2789
|
+
this.state.resultArr.push(value.valueOf());
|
|
2790
|
+
else this.state.resultArr.push(value);
|
|
2791
2791
|
return this.goto(this.parseInlineListNext);
|
|
2792
2792
|
}
|
|
2793
2793
|
parseInlineListNext() {
|
|
@@ -2799,34 +2799,34 @@ function makeParserClass(Parser11) {
|
|
|
2799
2799
|
}
|
|
2800
2800
|
/* INLINE TABLE */ parseInlineTable() {
|
|
2801
2801
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2802
|
-
else if (this.char ===
|
|
2802
|
+
else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) throw this.error(new TomlError("Unterminated inline array"));
|
|
2803
2803
|
else if (this.char === CHAR_RCUB) return this.return(this.state.resultTable || InlineTable());
|
|
2804
2804
|
else {
|
|
2805
2805
|
if (!this.state.resultTable) this.state.resultTable = InlineTable();
|
|
2806
2806
|
return this.callNow(this.parseAssign, this.recordInlineTableValue);
|
|
2807
2807
|
}
|
|
2808
2808
|
}
|
|
2809
|
-
recordInlineTableValue(
|
|
2810
|
-
let
|
|
2811
|
-
let
|
|
2812
|
-
for (let
|
|
2813
|
-
if (hasKey(
|
|
2814
|
-
|
|
2809
|
+
recordInlineTableValue(kv) {
|
|
2810
|
+
let target = this.state.resultTable;
|
|
2811
|
+
let finalKey = kv.key.pop();
|
|
2812
|
+
for (let kw of kv.key){
|
|
2813
|
+
if (hasKey(target, kw) && (!isTable(target[kw]) || target[kw][_declared])) throw this.error(new TomlError("Can't redefine existing key"));
|
|
2814
|
+
target = target[kw] = target[kw] || Table();
|
|
2815
2815
|
}
|
|
2816
|
-
if (hasKey(
|
|
2817
|
-
if (isInteger(
|
|
2818
|
-
else
|
|
2816
|
+
if (hasKey(target, finalKey)) throw this.error(new TomlError("Can't redefine existing key"));
|
|
2817
|
+
if (isInteger(kv.value) || isFloat(kv.value)) target[finalKey] = kv.value.valueOf();
|
|
2818
|
+
else target[finalKey] = kv.value;
|
|
2819
2819
|
return this.goto(this.parseInlineTableNext);
|
|
2820
2820
|
}
|
|
2821
2821
|
parseInlineTableNext() {
|
|
2822
2822
|
if (this.char === CHAR_SP || this.char === CTRL_I) return null;
|
|
2823
|
-
else if (this.char ===
|
|
2823
|
+
else if (this.char === Parser.END || this.char === CHAR_NUM || this.char === CTRL_J || this.char === CTRL_M) throw this.error(new TomlError("Unterminated inline array"));
|
|
2824
2824
|
else if (this.char === CHAR_COMMA) return this.next(this.parseInlineTable);
|
|
2825
2825
|
else if (this.char === CHAR_RCUB) return this.goto(this.parseInlineTable);
|
|
2826
2826
|
else throw this.error(new TomlError("Invalid character, expected whitespace, comma (,) or close bracket (])"));
|
|
2827
2827
|
}
|
|
2828
2828
|
}
|
|
2829
|
-
return
|
|
2829
|
+
return TOMLParser;
|
|
2830
2830
|
}
|
|
2831
2831
|
|
|
2832
2832
|
});
|