@formatjs/icu-messageformat-parser
Advanced tools
Comparing version 2.7.0 to 2.7.1
@@ -66,2 +66,2 @@ "use strict"; | ||
ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG"; | ||
})(ErrorKind = exports.ErrorKind || (exports.ErrorKind = {})); | ||
})(ErrorKind || (exports.ErrorKind = ErrorKind = {})); |
@@ -1,2 +0,5 @@ | ||
import { timeData } from './time-data.generated'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBestPattern = void 0; | ||
var time_data_generated_1 = require("./time-data.generated"); | ||
/** | ||
@@ -9,3 +12,3 @@ * Returns the best matching date time pattern if a date time skeleton | ||
*/ | ||
export function getBestPattern(skeleton, locale) { | ||
function getBestPattern(skeleton, locale) { | ||
var skeletonCopy = ''; | ||
@@ -44,2 +47,3 @@ for (var patternPos = 0; patternPos < skeleton.length; patternPos++) { | ||
} | ||
exports.getBestPattern = getBestPattern; | ||
/** | ||
@@ -80,7 +84,7 @@ * Maps the [hour cycle type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle) | ||
} | ||
var hourCycles = timeData[regionTag || ''] || | ||
timeData[languageTag || ''] || | ||
timeData["".concat(languageTag, "-001")] || | ||
timeData['001']; | ||
var hourCycles = time_data_generated_1.timeData[regionTag || ''] || | ||
time_data_generated_1.timeData[languageTag || ''] || | ||
time_data_generated_1.timeData["".concat(languageTag, "-001")] || | ||
time_data_generated_1.timeData['001']; | ||
return hourCycles[0]; | ||
} |
@@ -1,2 +0,5 @@ | ||
export var ErrorKind; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ErrorKind = void 0; | ||
var ErrorKind; | ||
(function (ErrorKind) { | ||
@@ -63,2 +66,2 @@ /** Argument is unclosed (e.g. `{0`) */ | ||
ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG"; | ||
})(ErrorKind || (ErrorKind = {})); | ||
})(ErrorKind || (exports.ErrorKind = ErrorKind = {})); |
@@ -1,9 +0,12 @@ | ||
import { __assign } from "tslib"; | ||
import { ErrorKind } from './error'; | ||
import { Parser } from './parser'; | ||
import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._Parser = exports.parse = void 0; | ||
var tslib_1 = require("tslib"); | ||
var error_1 = require("./error"); | ||
var parser_1 = require("./parser"); | ||
var types_1 = require("./types"); | ||
function pruneLocation(els) { | ||
els.forEach(function (el) { | ||
delete el.location; | ||
if (isSelectElement(el) || isPluralElement(el)) { | ||
if ((0, types_1.isSelectElement)(el) || (0, types_1.isPluralElement)(el)) { | ||
for (var k in el.options) { | ||
@@ -14,10 +17,10 @@ delete el.options[k].location; | ||
} | ||
else if (isNumberElement(el) && isNumberSkeleton(el.style)) { | ||
else if ((0, types_1.isNumberElement)(el) && (0, types_1.isNumberSkeleton)(el.style)) { | ||
delete el.style.location; | ||
} | ||
else if ((isDateElement(el) || isTimeElement(el)) && | ||
isDateTimeSkeleton(el.style)) { | ||
else if (((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el)) && | ||
(0, types_1.isDateTimeSkeleton)(el.style)) { | ||
delete el.style.location; | ||
} | ||
else if (isTagElement(el)) { | ||
else if ((0, types_1.isTagElement)(el)) { | ||
pruneLocation(el.children); | ||
@@ -27,8 +30,8 @@ } | ||
} | ||
export function parse(message, opts) { | ||
function parse(message, opts) { | ||
if (opts === void 0) { opts = {}; } | ||
opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); | ||
var result = new Parser(message, opts).parse(); | ||
opts = tslib_1.__assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); | ||
var result = new parser_1.Parser(message, opts).parse(); | ||
if (result.err) { | ||
var error = SyntaxError(ErrorKind[result.err.kind]); | ||
var error = SyntaxError(error_1.ErrorKind[result.err.kind]); | ||
// @ts-expect-error Assign to error object | ||
@@ -45,4 +48,5 @@ error.location = result.err.location; | ||
} | ||
export * from './types'; | ||
exports.parse = parse; | ||
tslib_1.__exportStar(require("./types"), exports); | ||
// only for testing | ||
export var _Parser = Parser; | ||
exports._Parser = parser_1.Parser; |
@@ -1,7 +0,10 @@ | ||
import { __spreadArray } from "tslib"; | ||
import { isPluralElement, isSelectElement, isTagElement, } from './types'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hoistSelectors = void 0; | ||
var tslib_1 = require("tslib"); | ||
var types_1 = require("./types"); | ||
function cloneDeep(obj) { | ||
if (Array.isArray(obj)) { | ||
// @ts-expect-error meh | ||
return __spreadArray([], obj.map(cloneDeep), true); | ||
return tslib_1.__spreadArray([], obj.map(cloneDeep), true); | ||
} | ||
@@ -23,3 +26,3 @@ if (obj !== null && typeof obj === 'object') { | ||
cloned.options = Object.keys(options).reduce(function (all, k) { | ||
var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true)); | ||
var newValue = hoistSelectors(tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true)); | ||
all[k] = { | ||
@@ -33,3 +36,3 @@ value: newValue, | ||
function isPluralOrSelectElement(el) { | ||
return isPluralElement(el) || isSelectElement(el); | ||
return (0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el); | ||
} | ||
@@ -41,3 +44,3 @@ function findPluralOrSelectElement(ast) { | ||
} | ||
if (isTagElement(el)) { | ||
if ((0, types_1.isTagElement)(el)) { | ||
return findPluralOrSelectElement(el.children); | ||
@@ -59,3 +62,3 @@ } | ||
*/ | ||
export function hoistSelectors(ast) { | ||
function hoistSelectors(ast) { | ||
for (var i = 0; i < ast.length; i++) { | ||
@@ -66,3 +69,3 @@ var el = ast[i]; | ||
} | ||
if (isTagElement(el) && findPluralOrSelectElement([el])) { | ||
if ((0, types_1.isTagElement)(el) && findPluralOrSelectElement([el])) { | ||
throw new Error('Cannot hoist plural/select within a tag element. Please put the tag element inside each plural/select option'); | ||
@@ -73,1 +76,2 @@ } | ||
} | ||
exports.hoistSelectors = hoistSelectors; |
@@ -1,5 +0,10 @@ | ||
export function parse() { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports._Parser = exports.parse = void 0; | ||
var tslib_1 = require("tslib"); | ||
function parse() { | ||
throw new Error("You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead"); | ||
} | ||
export * from './types'; | ||
export var _Parser = undefined; | ||
exports.parse = parse; | ||
tslib_1.__exportStar(require("./types"), exports); | ||
exports._Parser = undefined; |
@@ -0,10 +1,13 @@ | ||
"use strict"; | ||
var _a; | ||
import { __assign } from "tslib"; | ||
import { ErrorKind } from './error'; | ||
import { SKELETON_TYPE, TYPE, } from './types'; | ||
import { SPACE_SEPARATOR_REGEX } from './regex.generated'; | ||
import { parseNumberSkeleton, parseNumberSkeletonFromString, parseDateTimeSkeleton, } from '@formatjs/icu-skeleton-parser'; | ||
import { getBestPattern } from './date-time-pattern-generator'; | ||
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*")); | ||
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$")); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Parser = void 0; | ||
var tslib_1 = require("tslib"); | ||
var error_1 = require("./error"); | ||
var types_1 = require("./types"); | ||
var regex_generated_1 = require("./regex.generated"); | ||
var icu_skeleton_parser_1 = require("@formatjs/icu-skeleton-parser"); | ||
var date_time_pattern_generator_1 = require("./date-time-pattern-generator"); | ||
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(regex_generated_1.SPACE_SEPARATOR_REGEX.source, "*")); | ||
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(regex_generated_1.SPACE_SEPARATOR_REGEX.source, "*$")); | ||
function createLocation(start, end) { | ||
@@ -195,3 +198,3 @@ return { start: start, end: end }; | ||
elements.push({ | ||
type: TYPE.pound, | ||
type: types_1.TYPE.pound, | ||
location: createLocation(position, this.clonePosition()), | ||
@@ -208,3 +211,3 @@ }); | ||
else { | ||
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); | ||
return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
@@ -258,3 +261,3 @@ } | ||
val: { | ||
type: TYPE.literal, | ||
type: types_1.TYPE.literal, | ||
value: "<".concat(tagName, "/>"), | ||
@@ -276,3 +279,3 @@ location: createLocation(startPosition, this.clonePosition()), | ||
if (this.isEOF() || !_isAlpha(this.char())) { | ||
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
} | ||
@@ -282,11 +285,11 @@ var closingTagNameStartPosition = this.clonePosition(); | ||
if (tagName !== closingTagName) { | ||
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); | ||
} | ||
this.bumpSpace(); | ||
if (!this.bumpIf('>')) { | ||
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
} | ||
return { | ||
val: { | ||
type: TYPE.tag, | ||
type: types_1.TYPE.tag, | ||
value: tagName, | ||
@@ -300,7 +303,7 @@ children: children, | ||
else { | ||
return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); | ||
} | ||
} | ||
else { | ||
return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); | ||
} | ||
@@ -342,3 +345,3 @@ }; | ||
return { | ||
val: { type: TYPE.literal, value: value, location: location }, | ||
val: { type: types_1.TYPE.literal, value: value, location: location }, | ||
err: null, | ||
@@ -436,7 +439,7 @@ }; | ||
if (this.isEOF()) { | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
if (this.char() === 125 /* `}` */) { | ||
this.bump(); | ||
return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
@@ -446,7 +449,7 @@ // argument name | ||
if (!value) { | ||
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
this.bumpSpace(); | ||
if (this.isEOF()) { | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
@@ -459,3 +462,3 @@ switch (this.char()) { | ||
val: { | ||
type: TYPE.argument, | ||
type: types_1.TYPE.argument, | ||
// value does not include the opening and closing braces. | ||
@@ -473,3 +476,3 @@ value: value, | ||
if (this.isEOF()) { | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
@@ -479,3 +482,3 @@ return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition); | ||
default: | ||
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
@@ -508,3 +511,3 @@ }; | ||
// Expecting a style string number, date, time, plural, selectordinal, or select. | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
case 'number': | ||
@@ -527,3 +530,3 @@ case 'date': | ||
if (style.length === 0) { | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
@@ -548,3 +551,3 @@ var styleLocation = createLocation(styleStartPosition, this.clonePosition()); | ||
return { | ||
val: { type: TYPE.number, value: value, location: location_1, style: result.val }, | ||
val: { type: types_1.TYPE.number, value: value, location: location_1, style: result.val }, | ||
err: null, | ||
@@ -555,3 +558,3 @@ }; | ||
if (skeleton.length === 0) { | ||
return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); | ||
return this.error(error_1.ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); | ||
} | ||
@@ -563,13 +566,13 @@ var dateTimePattern = skeleton; | ||
if (this.locale) { | ||
dateTimePattern = getBestPattern(skeleton, this.locale); | ||
dateTimePattern = (0, date_time_pattern_generator_1.getBestPattern)(skeleton, this.locale); | ||
} | ||
var style = { | ||
type: SKELETON_TYPE.dateTime, | ||
type: types_1.SKELETON_TYPE.dateTime, | ||
pattern: dateTimePattern, | ||
location: styleAndLocation.styleLocation, | ||
parsedOptions: this.shouldParseSkeletons | ||
? parseDateTimeSkeleton(dateTimePattern) | ||
? (0, icu_skeleton_parser_1.parseDateTimeSkeleton)(dateTimePattern) | ||
: {}, | ||
}; | ||
var type = argType === 'date' ? TYPE.date : TYPE.time; | ||
var type = argType === 'date' ? types_1.TYPE.date : types_1.TYPE.time; | ||
return { | ||
@@ -585,6 +588,6 @@ val: { type: type, value: value, location: location_1, style: style }, | ||
type: argType === 'number' | ||
? TYPE.number | ||
? types_1.TYPE.number | ||
: argType === 'date' | ||
? TYPE.date | ||
: TYPE.time, | ||
? types_1.TYPE.date | ||
: types_1.TYPE.time, | ||
value: value, | ||
@@ -606,3 +609,3 @@ location: location_1, | ||
if (!this.bumpIf(',')) { | ||
return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, __assign({}, typeEndPosition_1))); | ||
return this.error(error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, tslib_1.__assign({}, typeEndPosition_1))); | ||
} | ||
@@ -622,6 +625,6 @@ this.bumpSpace(); | ||
if (!this.bumpIf(':')) { | ||
return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
this.bumpSpace(); | ||
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE); | ||
var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE); | ||
if (result.err) { | ||
@@ -647,3 +650,3 @@ return result; | ||
val: { | ||
type: TYPE.select, | ||
type: types_1.TYPE.select, | ||
value: value, | ||
@@ -659,3 +662,3 @@ options: fromEntries(optionsResult.val), | ||
val: { | ||
type: TYPE.plural, | ||
type: types_1.TYPE.plural, | ||
value: value, | ||
@@ -672,3 +675,3 @@ options: fromEntries(optionsResult.val), | ||
default: | ||
return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
return this.error(error_1.ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
} | ||
@@ -680,3 +683,3 @@ }; | ||
if (this.isEOF() || this.char() !== 125 /* `}` */) { | ||
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
} | ||
@@ -701,3 +704,3 @@ this.bump(); // `}` | ||
if (!this.bumpUntil("'")) { | ||
return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition())); | ||
return this.error(error_1.ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition())); | ||
} | ||
@@ -737,14 +740,14 @@ this.bump(); | ||
try { | ||
tokens = parseNumberSkeletonFromString(skeleton); | ||
tokens = (0, icu_skeleton_parser_1.parseNumberSkeletonFromString)(skeleton); | ||
} | ||
catch (e) { | ||
return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location); | ||
return this.error(error_1.ErrorKind.INVALID_NUMBER_SKELETON, location); | ||
} | ||
return { | ||
val: { | ||
type: SKELETON_TYPE.number, | ||
type: types_1.SKELETON_TYPE.number, | ||
tokens: tokens, | ||
location: location, | ||
parsedOptions: this.shouldParseSkeletons | ||
? parseNumberSkeleton(tokens) | ||
? (0, icu_skeleton_parser_1.parseNumberSkeleton)(tokens) | ||
: {}, | ||
@@ -779,3 +782,3 @@ }, | ||
// Try parse `={number}` selector | ||
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR); | ||
var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR); | ||
if (result.err) { | ||
@@ -794,4 +797,4 @@ return result; | ||
return this.error(parentArgType === 'select' | ||
? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR | ||
: ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation); | ||
? error_1.ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR | ||
: error_1.ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation); | ||
} | ||
@@ -808,4 +811,4 @@ if (selector === 'other') { | ||
return this.error(parentArgType === 'select' | ||
? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT | ||
: ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition())); | ||
? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT | ||
: error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
@@ -835,7 +838,7 @@ var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag); | ||
return this.error(parentArgType === 'select' | ||
? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR | ||
: ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition())); | ||
? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR | ||
: error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
if (this.requiresOtherClause && !hasOtherClause) { | ||
return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition())); | ||
return this.error(error_1.ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition())); | ||
} | ||
@@ -1006,3 +1009,3 @@ return { val: options, err: null }; | ||
}()); | ||
export { Parser }; | ||
exports.Parser = Parser; | ||
/** | ||
@@ -1009,0 +1012,0 @@ * This check if codepoint is alphabet (lower & uppercase) |
@@ -1,27 +0,31 @@ | ||
import { __spreadArray } from "tslib"; | ||
import { isLiteralElement, isTagElement, isSelectElement, isArgumentElement, isDateElement, isTimeElement, isNumberElement, isPluralElement, TYPE, SKELETON_TYPE, isPoundElement, } from './types'; | ||
export function printAST(ast) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.printDateTimeSkeleton = exports.doPrintAST = exports.printAST = void 0; | ||
var tslib_1 = require("tslib"); | ||
var types_1 = require("./types"); | ||
function printAST(ast) { | ||
return doPrintAST(ast, false); | ||
} | ||
export function doPrintAST(ast, isInPlural) { | ||
exports.printAST = printAST; | ||
function doPrintAST(ast, isInPlural) { | ||
var printedNodes = ast.map(function (el, i) { | ||
if (isLiteralElement(el)) { | ||
if ((0, types_1.isLiteralElement)(el)) { | ||
return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1); | ||
} | ||
if (isArgumentElement(el)) { | ||
if ((0, types_1.isArgumentElement)(el)) { | ||
return printArgumentElement(el); | ||
} | ||
if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) { | ||
if ((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el) || (0, types_1.isNumberElement)(el)) { | ||
return printSimpleFormatElement(el); | ||
} | ||
if (isPluralElement(el)) { | ||
if ((0, types_1.isPluralElement)(el)) { | ||
return printPluralElement(el); | ||
} | ||
if (isSelectElement(el)) { | ||
if ((0, types_1.isSelectElement)(el)) { | ||
return printSelectElement(el); | ||
} | ||
if (isPoundElement(el)) { | ||
if ((0, types_1.isPoundElement)(el)) { | ||
return '#'; | ||
} | ||
if (isTagElement(el)) { | ||
if ((0, types_1.isTagElement)(el)) { | ||
return printTagElement(el); | ||
@@ -32,2 +36,3 @@ } | ||
} | ||
exports.doPrintAST = doPrintAST; | ||
function printTagElement(el) { | ||
@@ -59,3 +64,3 @@ return "<".concat(el.value, ">").concat(printAST(el.children), "</").concat(el.value, ">"); | ||
function printSimpleFormatElement(el) { | ||
return "{".concat(el.value, ", ").concat(TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}"); | ||
return "{".concat(el.value, ", ").concat(types_1.TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}"); | ||
} | ||
@@ -72,3 +77,3 @@ function printNumberSkeletonToken(token) { | ||
} | ||
else if (style.type === SKELETON_TYPE.dateTime) { | ||
else if (style.type === types_1.SKELETON_TYPE.dateTime) { | ||
return "::".concat(printDateTimeSkeleton(style)); | ||
@@ -80,5 +85,6 @@ } | ||
} | ||
export function printDateTimeSkeleton(style) { | ||
function printDateTimeSkeleton(style) { | ||
return style.pattern; | ||
} | ||
exports.printDateTimeSkeleton = printDateTimeSkeleton; | ||
function printSelectElement(el) { | ||
@@ -99,3 +105,3 @@ var msg = [ | ||
type, | ||
__spreadArray([ | ||
tslib_1.__spreadArray([ | ||
el.offset ? "offset:".concat(el.offset) : '' | ||
@@ -102,0 +108,0 @@ ], Object.keys(el.options).map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, true), "}"); }), true).filter(Boolean) |
@@ -0,3 +1,6 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WHITE_SPACE_REGEX = exports.SPACE_SEPARATOR_REGEX = void 0; | ||
// @generated from regex-gen.ts | ||
export var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/; | ||
export var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/; | ||
exports.SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/; | ||
exports.WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/; |
@@ -0,4 +1,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.timeData = void 0; | ||
// @generated from time-data-gen.ts | ||
// prettier-ignore | ||
export var timeData = { | ||
exports.timeData = { | ||
"001": [ | ||
@@ -5,0 +8,0 @@ "H", |
@@ -1,2 +0,5 @@ | ||
export var TYPE; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createNumberElement = exports.createLiteralElement = exports.isDateTimeSkeleton = exports.isNumberSkeleton = exports.isTagElement = exports.isPoundElement = exports.isPluralElement = exports.isSelectElement = exports.isTimeElement = exports.isDateElement = exports.isNumberElement = exports.isArgumentElement = exports.isLiteralElement = exports.SKELETON_TYPE = exports.TYPE = void 0; | ||
var TYPE; | ||
(function (TYPE) { | ||
@@ -40,45 +43,56 @@ /** | ||
TYPE[TYPE["tag"] = 8] = "tag"; | ||
})(TYPE || (TYPE = {})); | ||
export var SKELETON_TYPE; | ||
})(TYPE || (exports.TYPE = TYPE = {})); | ||
var SKELETON_TYPE; | ||
(function (SKELETON_TYPE) { | ||
SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number"; | ||
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime"; | ||
})(SKELETON_TYPE || (SKELETON_TYPE = {})); | ||
})(SKELETON_TYPE || (exports.SKELETON_TYPE = SKELETON_TYPE = {})); | ||
/** | ||
* Type Guards | ||
*/ | ||
export function isLiteralElement(el) { | ||
function isLiteralElement(el) { | ||
return el.type === TYPE.literal; | ||
} | ||
export function isArgumentElement(el) { | ||
exports.isLiteralElement = isLiteralElement; | ||
function isArgumentElement(el) { | ||
return el.type === TYPE.argument; | ||
} | ||
export function isNumberElement(el) { | ||
exports.isArgumentElement = isArgumentElement; | ||
function isNumberElement(el) { | ||
return el.type === TYPE.number; | ||
} | ||
export function isDateElement(el) { | ||
exports.isNumberElement = isNumberElement; | ||
function isDateElement(el) { | ||
return el.type === TYPE.date; | ||
} | ||
export function isTimeElement(el) { | ||
exports.isDateElement = isDateElement; | ||
function isTimeElement(el) { | ||
return el.type === TYPE.time; | ||
} | ||
export function isSelectElement(el) { | ||
exports.isTimeElement = isTimeElement; | ||
function isSelectElement(el) { | ||
return el.type === TYPE.select; | ||
} | ||
export function isPluralElement(el) { | ||
exports.isSelectElement = isSelectElement; | ||
function isPluralElement(el) { | ||
return el.type === TYPE.plural; | ||
} | ||
export function isPoundElement(el) { | ||
exports.isPluralElement = isPluralElement; | ||
function isPoundElement(el) { | ||
return el.type === TYPE.pound; | ||
} | ||
export function isTagElement(el) { | ||
exports.isPoundElement = isPoundElement; | ||
function isTagElement(el) { | ||
return el.type === TYPE.tag; | ||
} | ||
export function isNumberSkeleton(el) { | ||
exports.isTagElement = isTagElement; | ||
function isNumberSkeleton(el) { | ||
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number); | ||
} | ||
export function isDateTimeSkeleton(el) { | ||
exports.isNumberSkeleton = isNumberSkeleton; | ||
function isDateTimeSkeleton(el) { | ||
return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime); | ||
} | ||
export function createLiteralElement(value) { | ||
exports.isDateTimeSkeleton = isDateTimeSkeleton; | ||
function createLiteralElement(value) { | ||
return { | ||
@@ -89,3 +103,4 @@ type: TYPE.literal, | ||
} | ||
export function createNumberElement(value, style) { | ||
exports.createLiteralElement = createLiteralElement; | ||
function createNumberElement(value, style) { | ||
return { | ||
@@ -97,1 +112,2 @@ type: TYPE.number, | ||
} | ||
exports.createNumberElement = createNumberElement; |
{ | ||
"name": "@formatjs/icu-messageformat-parser", | ||
"version": "2.7.0", | ||
"version": "2.7.1", | ||
"main": "index.js", | ||
@@ -15,5 +15,5 @@ "module": "lib/index.js", | ||
"tslib": "^2.4.0", | ||
"@formatjs/ecma402-abstract": "1.17.2", | ||
"@formatjs/icu-skeleton-parser": "1.6.2" | ||
"@formatjs/ecma402-abstract": "1.17.3", | ||
"@formatjs/icu-skeleton-parser": "1.6.3" | ||
} | ||
} |
@@ -43,3 +43,3 @@ "use strict"; | ||
TYPE[TYPE["tag"] = 8] = "tag"; | ||
})(TYPE = exports.TYPE || (exports.TYPE = {})); | ||
})(TYPE || (exports.TYPE = TYPE = {})); | ||
var SKELETON_TYPE; | ||
@@ -49,3 +49,3 @@ (function (SKELETON_TYPE) { | ||
SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime"; | ||
})(SKELETON_TYPE = exports.SKELETON_TYPE || (exports.SKELETON_TYPE = {})); | ||
})(SKELETON_TYPE || (exports.SKELETON_TYPE = SKELETON_TYPE = {})); | ||
/** | ||
@@ -52,0 +52,0 @@ * Type Guards |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
205248
7158
+ Added@formatjs/ecma402-abstract@1.17.3(transitive)
+ Added@formatjs/icu-skeleton-parser@1.6.3(transitive)
+ Added@formatjs/intl-localematcher@0.5.0(transitive)
- Removed@formatjs/ecma402-abstract@1.17.2(transitive)
- Removed@formatjs/icu-skeleton-parser@1.6.2(transitive)
- Removed@formatjs/intl-localematcher@0.4.2(transitive)