@formatjs/icu-messageformat-parser
Advanced tools
@@ -1,5 +0,2 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getBestPattern = getBestPattern; | ||
| var time_data_generated_1 = require("./time-data.generated"); | ||
| import { timeData } from './time-data.generated.js'; | ||
| /** | ||
@@ -12,3 +9,3 @@ * Returns the best matching date time pattern if a date time skeleton | ||
| */ | ||
| function getBestPattern(skeleton, locale) { | ||
| export function getBestPattern(skeleton, locale) { | ||
| var skeletonCopy = ''; | ||
@@ -82,7 +79,7 @@ for (var patternPos = 0; patternPos < skeleton.length; patternPos++) { | ||
| } | ||
| 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']; | ||
| var hourCycles = timeData[regionTag || ''] || | ||
| timeData[languageTag || ''] || | ||
| timeData["".concat(languageTag, "-001")] || | ||
| timeData['001']; | ||
| return hourCycles[0]; | ||
| } |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { Location } from './types'; | ||
| import { Location } from './types.js'; | ||
| export interface ParserError { | ||
@@ -3,0 +3,0 @@ kind: ErrorKind; |
+2
-5
@@ -1,5 +0,2 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ErrorKind = void 0; | ||
| var ErrorKind; | ||
| export var ErrorKind; | ||
| (function (ErrorKind) { | ||
@@ -66,2 +63,2 @@ /** Argument is unclosed (e.g. `{0`) */ | ||
| ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG"; | ||
| })(ErrorKind || (exports.ErrorKind = ErrorKind = {})); | ||
| })(ErrorKind || (ErrorKind = {})); |
+4
-4
@@ -1,7 +0,7 @@ | ||
| import { Parser, ParserOptions } from './parser'; | ||
| import { MessageFormatElement } from './types'; | ||
| import { Parser, ParserOptions } from './parser.js'; | ||
| import { MessageFormatElement } from './types.js'; | ||
| export declare function parse(message: string, opts?: ParserOptions): MessageFormatElement[]; | ||
| export * from './types'; | ||
| export * from './types.js'; | ||
| export type { ParserOptions }; | ||
| export declare const _Parser: typeof Parser; | ||
| export { isStructurallySame } from './manipulator'; | ||
| export { isStructurallySame } from './manipulator.js'; |
+16
-21
@@ -1,13 +0,9 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isStructurallySame = exports._Parser = void 0; | ||
| exports.parse = parse; | ||
| var tslib_1 = require("tslib"); | ||
| var error_1 = require("./error"); | ||
| var parser_1 = require("./parser"); | ||
| var types_1 = require("./types"); | ||
| import { __assign } from "tslib"; | ||
| import { ErrorKind } from './error.js'; | ||
| import { Parser } from './parser.js'; | ||
| import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types.js'; | ||
| function pruneLocation(els) { | ||
| els.forEach(function (el) { | ||
| delete el.location; | ||
| if ((0, types_1.isSelectElement)(el) || (0, types_1.isPluralElement)(el)) { | ||
| if (isSelectElement(el) || isPluralElement(el)) { | ||
| for (var k in el.options) { | ||
@@ -18,10 +14,10 @@ delete el.options[k].location; | ||
| } | ||
| else if ((0, types_1.isNumberElement)(el) && (0, types_1.isNumberSkeleton)(el.style)) { | ||
| else if (isNumberElement(el) && isNumberSkeleton(el.style)) { | ||
| delete el.style.location; | ||
| } | ||
| else if (((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el)) && | ||
| (0, types_1.isDateTimeSkeleton)(el.style)) { | ||
| else if ((isDateElement(el) || isTimeElement(el)) && | ||
| isDateTimeSkeleton(el.style)) { | ||
| delete el.style.location; | ||
| } | ||
| else if ((0, types_1.isTagElement)(el)) { | ||
| else if (isTagElement(el)) { | ||
| pruneLocation(el.children); | ||
@@ -31,8 +27,8 @@ } | ||
| } | ||
| function parse(message, opts) { | ||
| export function parse(message, opts) { | ||
| if (opts === void 0) { opts = {}; } | ||
| opts = tslib_1.__assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); | ||
| var result = new parser_1.Parser(message, opts).parse(); | ||
| opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); | ||
| var result = new Parser(message, opts).parse(); | ||
| if (result.err) { | ||
| var error = SyntaxError(error_1.ErrorKind[result.err.kind]); | ||
| var error = SyntaxError(ErrorKind[result.err.kind]); | ||
| // @ts-expect-error Assign to error object | ||
@@ -49,6 +45,5 @@ error.location = result.err.location; | ||
| } | ||
| tslib_1.__exportStar(require("./types"), exports); | ||
| export * from './types.js'; | ||
| // only for testing | ||
| exports._Parser = parser_1.Parser; | ||
| var manipulator_1 = require("./manipulator"); | ||
| Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } }); | ||
| export var _Parser = Parser; | ||
| export { isStructurallySame } from './manipulator.js'; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { MessageFormatElement } from './types'; | ||
| import { MessageFormatElement } from './types.js'; | ||
| /** | ||
@@ -3,0 +3,0 @@ * Hoist all selectors to the beginning of the AST & flatten the |
+16
-20
@@ -1,11 +0,7 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.hoistSelectors = hoistSelectors; | ||
| exports.isStructurallySame = isStructurallySame; | ||
| var tslib_1 = require("tslib"); | ||
| var types_1 = require("./types"); | ||
| import { __spreadArray } from "tslib"; | ||
| import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types.js'; | ||
| function cloneDeep(obj) { | ||
| if (Array.isArray(obj)) { | ||
| // @ts-expect-error meh | ||
| return tslib_1.__spreadArray([], obj.map(cloneDeep), true); | ||
| return obj.map(cloneDeep); | ||
| } | ||
@@ -27,3 +23,3 @@ if (obj !== null && typeof obj === 'object') { | ||
| cloned.options = Object.keys(options).reduce(function (all, k) { | ||
| 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)); | ||
| var newValue = hoistSelectors(__spreadArray(__spreadArray(__spreadArray([], ast.slice(0, positionToInject), true), options[k].value, true), ast.slice(positionToInject + 1), true)); | ||
| all[k] = { | ||
@@ -37,3 +33,3 @@ value: newValue, | ||
| function isPluralOrSelectElement(el) { | ||
| return (0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el); | ||
| return isPluralElement(el) || isSelectElement(el); | ||
| } | ||
@@ -45,3 +41,3 @@ function findPluralOrSelectElement(ast) { | ||
| } | ||
| if ((0, types_1.isTagElement)(el)) { | ||
| if (isTagElement(el)) { | ||
| return findPluralOrSelectElement(el.children); | ||
@@ -63,3 +59,3 @@ } | ||
| */ | ||
| function hoistSelectors(ast) { | ||
| export function hoistSelectors(ast) { | ||
| for (var i = 0; i < ast.length; i++) { | ||
@@ -70,3 +66,3 @@ var el = ast[i]; | ||
| } | ||
| if ((0, types_1.isTagElement)(el) && findPluralOrSelectElement([el])) { | ||
| if (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'); | ||
@@ -85,6 +81,6 @@ } | ||
| ast.forEach(function (el) { | ||
| if ((0, types_1.isArgumentElement)(el) || | ||
| (0, types_1.isDateElement)(el) || | ||
| (0, types_1.isTimeElement)(el) || | ||
| (0, types_1.isNumberElement)(el)) { | ||
| if (isArgumentElement(el) || | ||
| isDateElement(el) || | ||
| isTimeElement(el) || | ||
| isNumberElement(el)) { | ||
| if (el.value in vars && vars.get(el.value) !== el.type) { | ||
@@ -95,3 +91,3 @@ throw new Error("Variable ".concat(el.value, " has conflicting types")); | ||
| } | ||
| if ((0, types_1.isPluralElement)(el) || (0, types_1.isSelectElement)(el)) { | ||
| if (isPluralElement(el) || isSelectElement(el)) { | ||
| vars.set(el.value, el.type); | ||
@@ -102,3 +98,3 @@ Object.keys(el.options).forEach(function (k) { | ||
| } | ||
| if ((0, types_1.isTagElement)(el)) { | ||
| if (isTagElement(el)) { | ||
| vars.set(el.value, el.type); | ||
@@ -116,3 +112,3 @@ collectVariables(el.children, vars); | ||
| */ | ||
| function isStructurallySame(a, b) { | ||
| export function isStructurallySame(a, b) { | ||
| var aVars = new Map(); | ||
@@ -143,3 +139,3 @@ var bVars = new Map(); | ||
| success: false, | ||
| error: new Error("Variable ".concat(key, " has conflicting types: ").concat(types_1.TYPE[type], " vs ").concat(types_1.TYPE[bType])), | ||
| error: new Error("Variable ".concat(key, " has conflicting types: ").concat(TYPE[type], " vs ").concat(TYPE[bType])), | ||
| }; | ||
@@ -146,0 +142,0 @@ } |
+2
-2
| export declare function parse(): void; | ||
| export * from './types'; | ||
| export * from './types.js'; | ||
| export declare const _Parser: undefined; | ||
| export { isStructurallySame } from './manipulator'; | ||
| export { isStructurallySame } from './manipulator.js'; |
+4
-10
@@ -1,12 +0,6 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isStructurallySame = exports._Parser = void 0; | ||
| exports.parse = parse; | ||
| var tslib_1 = require("tslib"); | ||
| function parse() { | ||
| export function parse() { | ||
| throw new Error("You're trying to format an uncompiled message with react-intl without parser, please import from 'react-intl' instead"); | ||
| } | ||
| tslib_1.__exportStar(require("./types"), exports); | ||
| exports._Parser = undefined; | ||
| var manipulator_1 = require("./manipulator"); | ||
| Object.defineProperty(exports, "isStructurallySame", { enumerable: true, get: function () { return manipulator_1.isStructurallySame; } }); | ||
| export * from './types.js'; | ||
| export var _Parser = undefined; | ||
| export { isStructurallySame } from './manipulator.js'; |
+14
-9
| { | ||
| "name": "@formatjs/icu-messageformat-parser", | ||
| "version": "2.11.4", | ||
| "license": "MIT", | ||
| "types": "index.d.ts", | ||
| "version": "3.0.0", | ||
| "dependencies": { | ||
| "tslib": "^2.8.0", | ||
| "@formatjs/icu-skeleton-parser": "1.8.16", | ||
| "@formatjs/ecma402-abstract": "2.3.6" | ||
| "@formatjs/ecma402-abstract": "3.0.0", | ||
| "@formatjs/icu-skeleton-parser": "2.0.0", | ||
| "tslib": "^2.8.0" | ||
| }, | ||
| "main": "index.js", | ||
| "module": "lib/index.js", | ||
| "exports": { | ||
| ".": "./index.js", | ||
| "./no-parser.js": "./no-parser.js", | ||
| "./printer.js": "./printer.js", | ||
| "./manipulator.js": "./manipulator.js" | ||
| }, | ||
| "license": "MIT", | ||
| "repository": { | ||
@@ -17,3 +20,5 @@ "type": "git", | ||
| "directory": "packages/icu-messageformat-parser" | ||
| } | ||
| }, | ||
| "type": "module", | ||
| "types": "index.d.ts" | ||
| } |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import { ParserError } from './error'; | ||
| import { MessageFormatElement } from './types'; | ||
| import { ParserError } from './error.js'; | ||
| import { MessageFormatElement } from './types.js'; | ||
| export interface Position { | ||
@@ -4,0 +4,0 @@ /** Offset in terms of UTF-16 *code unit*. */ |
+59
-62
@@ -1,13 +0,10 @@ | ||
| "use strict"; | ||
| var _a; | ||
| 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, "*$")); | ||
| import { __assign } from "tslib"; | ||
| import { ErrorKind } from './error.js'; | ||
| import { SKELETON_TYPE, TYPE, } from './types.js'; | ||
| import { SPACE_SEPARATOR_REGEX } from './regex.generated.js'; | ||
| import { parseNumberSkeleton, parseNumberSkeletonFromString, parseDateTimeSkeleton, } from '@formatjs/icu-skeleton-parser'; | ||
| import { getBestPattern } from './date-time-pattern-generator.js'; | ||
| var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*")); | ||
| var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$")); | ||
| function createLocation(start, end) { | ||
@@ -45,3 +42,3 @@ return { start: start, end: end }; | ||
| } | ||
| catch (_) { | ||
| catch (_b) { | ||
| REGEX_SUPPORTS_U_AND_Y = false; | ||
@@ -199,3 +196,3 @@ } | ||
| elements.push({ | ||
| type: types_1.TYPE.pound, | ||
| type: TYPE.pound, | ||
| location: createLocation(position, this.clonePosition()), | ||
@@ -212,3 +209,3 @@ }); | ||
| else { | ||
| return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); | ||
| return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
@@ -262,3 +259,3 @@ } | ||
| val: { | ||
| type: types_1.TYPE.literal, | ||
| type: TYPE.literal, | ||
| value: "<".concat(tagName, "/>"), | ||
@@ -280,3 +277,3 @@ location: createLocation(startPosition, this.clonePosition()), | ||
| if (this.isEOF() || !_isAlpha(this.char())) { | ||
| return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| } | ||
@@ -286,11 +283,11 @@ var closingTagNameStartPosition = this.clonePosition(); | ||
| if (tagName !== closingTagName) { | ||
| return this.error(error_1.ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); | ||
| return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); | ||
| } | ||
| this.bumpSpace(); | ||
| if (!this.bumpIf('>')) { | ||
| return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| } | ||
| return { | ||
| val: { | ||
| type: types_1.TYPE.tag, | ||
| type: TYPE.tag, | ||
| value: tagName, | ||
@@ -304,7 +301,7 @@ children: children, | ||
| else { | ||
| return this.error(error_1.ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); | ||
| return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); | ||
| } | ||
| } | ||
| else { | ||
| return this.error(error_1.ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); | ||
| } | ||
@@ -346,3 +343,3 @@ }; | ||
| return { | ||
| val: { type: types_1.TYPE.literal, value: value, location: location }, | ||
| val: { type: TYPE.literal, value: value, location: location }, | ||
| err: null, | ||
@@ -440,7 +437,7 @@ }; | ||
| if (this.isEOF()) { | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| if (this.char() === 125 /* `}` */) { | ||
| this.bump(); | ||
| return this.error(error_1.ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
@@ -450,7 +447,7 @@ // argument name | ||
| if (!value) { | ||
| return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| this.bumpSpace(); | ||
| if (this.isEOF()) { | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
@@ -463,3 +460,3 @@ switch (this.char()) { | ||
| val: { | ||
| type: types_1.TYPE.argument, | ||
| type: TYPE.argument, | ||
| // value does not include the opening and closing braces. | ||
@@ -477,3 +474,3 @@ value: value, | ||
| if (this.isEOF()) { | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
@@ -483,3 +480,3 @@ return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition); | ||
| default: | ||
| return this.error(error_1.ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
@@ -512,3 +509,3 @@ }; | ||
| // Expecting a style string number, date, time, plural, selectordinal, or select. | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| case 'number': | ||
@@ -531,3 +528,3 @@ case 'date': | ||
| if (style.length === 0) { | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
@@ -552,3 +549,3 @@ var styleLocation = createLocation(styleStartPosition, this.clonePosition()); | ||
| return { | ||
| val: { type: types_1.TYPE.number, value: value, location: location_1, style: result.val }, | ||
| val: { type: TYPE.number, value: value, location: location_1, style: result.val }, | ||
| err: null, | ||
@@ -559,3 +556,3 @@ }; | ||
| if (skeleton.length === 0) { | ||
| return this.error(error_1.ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); | ||
| return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); | ||
| } | ||
@@ -567,13 +564,13 @@ var dateTimePattern = skeleton; | ||
| if (this.locale) { | ||
| dateTimePattern = (0, date_time_pattern_generator_1.getBestPattern)(skeleton, this.locale); | ||
| dateTimePattern = getBestPattern(skeleton, this.locale); | ||
| } | ||
| var style = { | ||
| type: types_1.SKELETON_TYPE.dateTime, | ||
| type: SKELETON_TYPE.dateTime, | ||
| pattern: dateTimePattern, | ||
| location: styleAndLocation.styleLocation, | ||
| parsedOptions: this.shouldParseSkeletons | ||
| ? (0, icu_skeleton_parser_1.parseDateTimeSkeleton)(dateTimePattern) | ||
| ? parseDateTimeSkeleton(dateTimePattern) | ||
| : {}, | ||
| }; | ||
| var type = argType === 'date' ? types_1.TYPE.date : types_1.TYPE.time; | ||
| var type = argType === 'date' ? TYPE.date : TYPE.time; | ||
| return { | ||
@@ -589,6 +586,6 @@ val: { type: type, value: value, location: location_1, style: style }, | ||
| type: argType === 'number' | ||
| ? types_1.TYPE.number | ||
| ? TYPE.number | ||
| : argType === 'date' | ||
| ? types_1.TYPE.date | ||
| : types_1.TYPE.time, | ||
| ? TYPE.date | ||
| : TYPE.time, | ||
| value: value, | ||
@@ -610,3 +607,3 @@ location: location_1, | ||
| if (!this.bumpIf(',')) { | ||
| return this.error(error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, tslib_1.__assign({}, typeEndPosition_1))); | ||
| return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, __assign({}, typeEndPosition_1))); | ||
| } | ||
@@ -626,6 +623,6 @@ this.bumpSpace(); | ||
| if (!this.bumpIf(':')) { | ||
| return this.error(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
| this.bumpSpace(); | ||
| var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE); | ||
| var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE); | ||
| if (result.err) { | ||
@@ -651,3 +648,3 @@ return result; | ||
| val: { | ||
| type: types_1.TYPE.select, | ||
| type: TYPE.select, | ||
| value: value, | ||
@@ -663,3 +660,3 @@ options: fromEntries(optionsResult.val), | ||
| val: { | ||
| type: types_1.TYPE.plural, | ||
| type: TYPE.plural, | ||
| value: value, | ||
@@ -676,3 +673,3 @@ options: fromEntries(optionsResult.val), | ||
| default: | ||
| return this.error(error_1.ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| } | ||
@@ -684,3 +681,3 @@ }; | ||
| if (this.isEOF() || this.char() !== 125 /* `}` */) { | ||
| return this.error(error_1.ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
@@ -705,3 +702,3 @@ this.bump(); // `}` | ||
| if (!this.bumpUntil("'")) { | ||
| return this.error(error_1.ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition())); | ||
| return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition())); | ||
| } | ||
@@ -741,14 +738,14 @@ this.bump(); | ||
| try { | ||
| tokens = (0, icu_skeleton_parser_1.parseNumberSkeletonFromString)(skeleton); | ||
| tokens = parseNumberSkeletonFromString(skeleton); | ||
| } | ||
| catch (e) { | ||
| return this.error(error_1.ErrorKind.INVALID_NUMBER_SKELETON, location); | ||
| catch (_a) { | ||
| return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location); | ||
| } | ||
| return { | ||
| val: { | ||
| type: types_1.SKELETON_TYPE.number, | ||
| type: SKELETON_TYPE.number, | ||
| tokens: tokens, | ||
| location: location, | ||
| parsedOptions: this.shouldParseSkeletons | ||
| ? (0, icu_skeleton_parser_1.parseNumberSkeleton)(tokens) | ||
| ? parseNumberSkeleton(tokens) | ||
| : {}, | ||
@@ -783,3 +780,3 @@ }, | ||
| // Try parse `={number}` selector | ||
| var result = this.tryParseDecimalInteger(error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, error_1.ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR); | ||
| var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR); | ||
| if (result.err) { | ||
@@ -798,4 +795,4 @@ return result; | ||
| return this.error(parentArgType === 'select' | ||
| ? error_1.ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR | ||
| : error_1.ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation); | ||
| ? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR | ||
| : ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation); | ||
| } | ||
@@ -812,4 +809,4 @@ if (selector === 'other') { | ||
| return this.error(parentArgType === 'select' | ||
| ? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT | ||
| : error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition())); | ||
| ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT | ||
| : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
@@ -839,7 +836,7 @@ var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag); | ||
| return this.error(parentArgType === 'select' | ||
| ? error_1.ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR | ||
| : error_1.ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition())); | ||
| ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR | ||
| : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
| if (this.requiresOtherClause && !hasOtherClause) { | ||
| return this.error(error_1.ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
@@ -1010,3 +1007,3 @@ return { val: options, err: null }; | ||
| }()); | ||
| exports.Parser = Parser; | ||
| export { Parser }; | ||
| /** | ||
@@ -1013,0 +1010,0 @@ * This check if codepoint is alphabet (lower & uppercase) |
+1
-1
@@ -1,4 +0,4 @@ | ||
| import { DateTimeSkeleton, MessageFormatElement } from './types'; | ||
| import { DateTimeSkeleton, MessageFormatElement } from './types.js'; | ||
| export declare function printAST(ast: MessageFormatElement[]): string; | ||
| export declare function doPrintAST(ast: MessageFormatElement[], isInPlural: boolean): string; | ||
| export declare function printDateTimeSkeleton(style: DateTimeSkeleton): string; |
+15
-20
@@ -1,32 +0,27 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.printAST = printAST; | ||
| exports.doPrintAST = doPrintAST; | ||
| exports.printDateTimeSkeleton = printDateTimeSkeleton; | ||
| var tslib_1 = require("tslib"); | ||
| var types_1 = require("./types"); | ||
| function printAST(ast) { | ||
| import { __spreadArray } from "tslib"; | ||
| import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE, } from './types.js'; | ||
| export function printAST(ast) { | ||
| return doPrintAST(ast, false); | ||
| } | ||
| function doPrintAST(ast, isInPlural) { | ||
| export function doPrintAST(ast, isInPlural) { | ||
| var printedNodes = ast.map(function (el, i) { | ||
| if ((0, types_1.isLiteralElement)(el)) { | ||
| if (isLiteralElement(el)) { | ||
| return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1); | ||
| } | ||
| if ((0, types_1.isArgumentElement)(el)) { | ||
| if (isArgumentElement(el)) { | ||
| return printArgumentElement(el); | ||
| } | ||
| if ((0, types_1.isDateElement)(el) || (0, types_1.isTimeElement)(el) || (0, types_1.isNumberElement)(el)) { | ||
| if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) { | ||
| return printSimpleFormatElement(el); | ||
| } | ||
| if ((0, types_1.isPluralElement)(el)) { | ||
| if (isPluralElement(el)) { | ||
| return printPluralElement(el); | ||
| } | ||
| if ((0, types_1.isSelectElement)(el)) { | ||
| if (isSelectElement(el)) { | ||
| return printSelectElement(el); | ||
| } | ||
| if ((0, types_1.isPoundElement)(el)) { | ||
| if (isPoundElement(el)) { | ||
| return '#'; | ||
| } | ||
| if ((0, types_1.isTagElement)(el)) { | ||
| if (isTagElement(el)) { | ||
| return printTagElement(el); | ||
@@ -63,3 +58,3 @@ } | ||
| function printSimpleFormatElement(el) { | ||
| return "{".concat(el.value, ", ").concat(types_1.TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}"); | ||
| return "{".concat(el.value, ", ").concat(TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}"); | ||
| } | ||
@@ -76,3 +71,3 @@ function printNumberSkeletonToken(token) { | ||
| } | ||
| else if (style.type === types_1.SKELETON_TYPE.dateTime) { | ||
| else if (style.type === SKELETON_TYPE.dateTime) { | ||
| return "::".concat(printDateTimeSkeleton(style)); | ||
@@ -84,3 +79,3 @@ } | ||
| } | ||
| function printDateTimeSkeleton(style) { | ||
| export function printDateTimeSkeleton(style) { | ||
| return style.pattern; | ||
@@ -103,3 +98,3 @@ } | ||
| type, | ||
| tslib_1.__spreadArray([ | ||
| __spreadArray([ | ||
| el.offset ? "offset:".concat(el.offset) : '' | ||
@@ -106,0 +101,0 @@ ], Object.keys(el.options).map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, true), "}"); }), true).filter(Boolean) |
@@ -1,6 +0,3 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.WHITE_SPACE_REGEX = exports.SPACE_SEPARATOR_REGEX = void 0; | ||
| // @generated from regex-gen.ts | ||
| exports.SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/; | ||
| exports.WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/; | ||
| export var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/; | ||
| export var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/; |
@@ -1,7 +0,4 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.timeData = void 0; | ||
| // @generated from time-data-gen.ts | ||
| // prettier-ignore | ||
| exports.timeData = { | ||
| export var timeData = { | ||
| "001": [ | ||
@@ -8,0 +5,0 @@ "H", |
+17
-33
@@ -1,18 +0,2 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.SKELETON_TYPE = exports.TYPE = void 0; | ||
| exports.isLiteralElement = isLiteralElement; | ||
| exports.isArgumentElement = isArgumentElement; | ||
| exports.isNumberElement = isNumberElement; | ||
| exports.isDateElement = isDateElement; | ||
| exports.isTimeElement = isTimeElement; | ||
| exports.isSelectElement = isSelectElement; | ||
| exports.isPluralElement = isPluralElement; | ||
| exports.isPoundElement = isPoundElement; | ||
| exports.isTagElement = isTagElement; | ||
| exports.isNumberSkeleton = isNumberSkeleton; | ||
| exports.isDateTimeSkeleton = isDateTimeSkeleton; | ||
| exports.createLiteralElement = createLiteralElement; | ||
| exports.createNumberElement = createNumberElement; | ||
| var TYPE; | ||
| export var TYPE; | ||
| (function (TYPE) { | ||
@@ -56,45 +40,45 @@ /** | ||
| TYPE[TYPE["tag"] = 8] = "tag"; | ||
| })(TYPE || (exports.TYPE = TYPE = {})); | ||
| var SKELETON_TYPE; | ||
| })(TYPE || (TYPE = {})); | ||
| export var SKELETON_TYPE; | ||
| (function (SKELETON_TYPE) { | ||
| SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number"; | ||
| SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime"; | ||
| })(SKELETON_TYPE || (exports.SKELETON_TYPE = SKELETON_TYPE = {})); | ||
| })(SKELETON_TYPE || (SKELETON_TYPE = {})); | ||
| /** | ||
| * Type Guards | ||
| */ | ||
| function isLiteralElement(el) { | ||
| export function isLiteralElement(el) { | ||
| return el.type === TYPE.literal; | ||
| } | ||
| function isArgumentElement(el) { | ||
| export function isArgumentElement(el) { | ||
| return el.type === TYPE.argument; | ||
| } | ||
| function isNumberElement(el) { | ||
| export function isNumberElement(el) { | ||
| return el.type === TYPE.number; | ||
| } | ||
| function isDateElement(el) { | ||
| export function isDateElement(el) { | ||
| return el.type === TYPE.date; | ||
| } | ||
| function isTimeElement(el) { | ||
| export function isTimeElement(el) { | ||
| return el.type === TYPE.time; | ||
| } | ||
| function isSelectElement(el) { | ||
| export function isSelectElement(el) { | ||
| return el.type === TYPE.select; | ||
| } | ||
| function isPluralElement(el) { | ||
| export function isPluralElement(el) { | ||
| return el.type === TYPE.plural; | ||
| } | ||
| function isPoundElement(el) { | ||
| export function isPoundElement(el) { | ||
| return el.type === TYPE.pound; | ||
| } | ||
| function isTagElement(el) { | ||
| export function isTagElement(el) { | ||
| return el.type === TYPE.tag; | ||
| } | ||
| function isNumberSkeleton(el) { | ||
| export function isNumberSkeleton(el) { | ||
| return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number); | ||
| } | ||
| function isDateTimeSkeleton(el) { | ||
| export function isDateTimeSkeleton(el) { | ||
| return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime); | ||
| } | ||
| function createLiteralElement(value) { | ||
| export function createLiteralElement(value) { | ||
| return { | ||
@@ -105,3 +89,3 @@ type: TYPE.literal, | ||
| } | ||
| function createNumberElement(value, style) { | ||
| export function createNumberElement(value, style) { | ||
| return { | ||
@@ -108,0 +92,0 @@ type: TYPE.number, |
| /** | ||
| * Returns the best matching date time pattern if a date time skeleton | ||
| * pattern is provided with a locale. Follows the Unicode specification: | ||
| * https://www.unicode.org/reports/tr35/tr35-dates.html#table-mapping-requested-time-skeletons-to-patterns | ||
| * @param skeleton date time skeleton pattern that possibly includes j, J or C | ||
| * @param locale | ||
| */ | ||
| export declare function getBestPattern(skeleton: string, locale: Intl.Locale): string; |
| import { timeData } from './time-data.generated'; | ||
| /** | ||
| * Returns the best matching date time pattern if a date time skeleton | ||
| * pattern is provided with a locale. Follows the Unicode specification: | ||
| * https://www.unicode.org/reports/tr35/tr35-dates.html#table-mapping-requested-time-skeletons-to-patterns | ||
| * @param skeleton date time skeleton pattern that possibly includes j, J or C | ||
| * @param locale | ||
| */ | ||
| export function getBestPattern(skeleton, locale) { | ||
| var skeletonCopy = ''; | ||
| for (var patternPos = 0; patternPos < skeleton.length; patternPos++) { | ||
| var patternChar = skeleton.charAt(patternPos); | ||
| if (patternChar === 'j') { | ||
| var extraLength = 0; | ||
| while (patternPos + 1 < skeleton.length && | ||
| skeleton.charAt(patternPos + 1) === patternChar) { | ||
| extraLength++; | ||
| patternPos++; | ||
| } | ||
| var hourLen = 1 + (extraLength & 1); | ||
| var dayPeriodLen = extraLength < 2 ? 1 : 3 + (extraLength >> 1); | ||
| var dayPeriodChar = 'a'; | ||
| var hourChar = getDefaultHourSymbolFromLocale(locale); | ||
| if (hourChar == 'H' || hourChar == 'k') { | ||
| dayPeriodLen = 0; | ||
| } | ||
| while (dayPeriodLen-- > 0) { | ||
| skeletonCopy += dayPeriodChar; | ||
| } | ||
| while (hourLen-- > 0) { | ||
| skeletonCopy = hourChar + skeletonCopy; | ||
| } | ||
| } | ||
| else if (patternChar === 'J') { | ||
| skeletonCopy += 'H'; | ||
| } | ||
| else { | ||
| skeletonCopy += patternChar; | ||
| } | ||
| } | ||
| return skeletonCopy; | ||
| } | ||
| /** | ||
| * Maps the [hour cycle type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/hourCycle) | ||
| * of the given `locale` to the corresponding time pattern. | ||
| * @param locale | ||
| */ | ||
| function getDefaultHourSymbolFromLocale(locale) { | ||
| var hourCycle = locale.hourCycle; | ||
| if (hourCycle === undefined && | ||
| // @ts-ignore hourCycle(s) is not identified yet | ||
| locale.hourCycles && | ||
| // @ts-ignore | ||
| locale.hourCycles.length) { | ||
| // @ts-ignore | ||
| hourCycle = locale.hourCycles[0]; | ||
| } | ||
| if (hourCycle) { | ||
| switch (hourCycle) { | ||
| case 'h24': | ||
| return 'k'; | ||
| case 'h23': | ||
| return 'H'; | ||
| case 'h12': | ||
| return 'h'; | ||
| case 'h11': | ||
| return 'K'; | ||
| default: | ||
| throw new Error('Invalid hourCycle'); | ||
| } | ||
| } | ||
| // TODO: Once hourCycle is fully supported remove the following with data generation | ||
| var languageTag = locale.language; | ||
| var regionTag; | ||
| if (languageTag !== 'root') { | ||
| regionTag = locale.maximize().region; | ||
| } | ||
| var hourCycles = timeData[regionTag || ''] || | ||
| timeData[languageTag || ''] || | ||
| timeData["".concat(languageTag, "-001")] || | ||
| timeData['001']; | ||
| return hourCycles[0]; | ||
| } |
| import { Location } from './types'; | ||
| export interface ParserError { | ||
| kind: ErrorKind; | ||
| message: string; | ||
| location: Location; | ||
| } | ||
| export declare enum ErrorKind { | ||
| /** Argument is unclosed (e.g. `{0`) */ | ||
| EXPECT_ARGUMENT_CLOSING_BRACE = 1, | ||
| /** Argument is empty (e.g. `{}`). */ | ||
| EMPTY_ARGUMENT = 2, | ||
| /** Argument is malformed (e.g. `{foo!}``) */ | ||
| MALFORMED_ARGUMENT = 3, | ||
| /** Expect an argument type (e.g. `{foo,}`) */ | ||
| EXPECT_ARGUMENT_TYPE = 4, | ||
| /** Unsupported argument type (e.g. `{foo,foo}`) */ | ||
| INVALID_ARGUMENT_TYPE = 5, | ||
| /** Expect an argument style (e.g. `{foo, number, }`) */ | ||
| EXPECT_ARGUMENT_STYLE = 6, | ||
| /** The number skeleton is invalid. */ | ||
| INVALID_NUMBER_SKELETON = 7, | ||
| /** The date time skeleton is invalid. */ | ||
| INVALID_DATE_TIME_SKELETON = 8, | ||
| /** Exepct a number skeleton following the `::` (e.g. `{foo, number, ::}`) */ | ||
| EXPECT_NUMBER_SKELETON = 9, | ||
| /** Exepct a date time skeleton following the `::` (e.g. `{foo, date, ::}`) */ | ||
| EXPECT_DATE_TIME_SKELETON = 10, | ||
| /** Unmatched apostrophes in the argument style (e.g. `{foo, number, 'test`) */ | ||
| UNCLOSED_QUOTE_IN_ARGUMENT_STYLE = 11, | ||
| /** Missing select argument options (e.g. `{foo, select}`) */ | ||
| EXPECT_SELECT_ARGUMENT_OPTIONS = 12, | ||
| /** Expecting an offset value in `plural` or `selectordinal` argument (e.g `{foo, plural, offset}`) */ | ||
| EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE = 13, | ||
| /** Offset value in `plural` or `selectordinal` is invalid (e.g. `{foo, plural, offset: x}`) */ | ||
| INVALID_PLURAL_ARGUMENT_OFFSET_VALUE = 14, | ||
| /** Expecting a selector in `select` argument (e.g `{foo, select}`) */ | ||
| EXPECT_SELECT_ARGUMENT_SELECTOR = 15, | ||
| /** Expecting a selector in `plural` or `selectordinal` argument (e.g `{foo, plural}`) */ | ||
| EXPECT_PLURAL_ARGUMENT_SELECTOR = 16, | ||
| /** Expecting a message fragment after the `select` selector (e.g. `{foo, select, apple}`) */ | ||
| EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT = 17, | ||
| /** | ||
| * Expecting a message fragment after the `plural` or `selectordinal` selector | ||
| * (e.g. `{foo, plural, one}`) | ||
| */ | ||
| EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT = 18, | ||
| /** Selector in `plural` or `selectordinal` is malformed (e.g. `{foo, plural, =x {#}}`) */ | ||
| INVALID_PLURAL_ARGUMENT_SELECTOR = 19, | ||
| /** | ||
| * Duplicate selectors in `plural` or `selectordinal` argument. | ||
| * (e.g. {foo, plural, one {#} one {#}}) | ||
| */ | ||
| DUPLICATE_PLURAL_ARGUMENT_SELECTOR = 20, | ||
| /** Duplicate selectors in `select` argument. | ||
| * (e.g. {foo, select, apple {apple} apple {apple}}) | ||
| */ | ||
| DUPLICATE_SELECT_ARGUMENT_SELECTOR = 21, | ||
| /** Plural or select argument option must have `other` clause. */ | ||
| MISSING_OTHER_CLAUSE = 22, | ||
| /** The tag is malformed. (e.g. `<bold!>foo</bold!>) */ | ||
| INVALID_TAG = 23, | ||
| /** The tag name is invalid. (e.g. `<123>foo</123>`) */ | ||
| INVALID_TAG_NAME = 25, | ||
| /** The closing tag does not match the opening tag. (e.g. `<bold>foo</italic>`) */ | ||
| UNMATCHED_CLOSING_TAG = 26, | ||
| /** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */ | ||
| UNCLOSED_TAG = 27 | ||
| } |
-63
| export var ErrorKind; | ||
| (function (ErrorKind) { | ||
| /** Argument is unclosed (e.g. `{0`) */ | ||
| ErrorKind[ErrorKind["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE"; | ||
| /** Argument is empty (e.g. `{}`). */ | ||
| ErrorKind[ErrorKind["EMPTY_ARGUMENT"] = 2] = "EMPTY_ARGUMENT"; | ||
| /** Argument is malformed (e.g. `{foo!}``) */ | ||
| ErrorKind[ErrorKind["MALFORMED_ARGUMENT"] = 3] = "MALFORMED_ARGUMENT"; | ||
| /** Expect an argument type (e.g. `{foo,}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_ARGUMENT_TYPE"] = 4] = "EXPECT_ARGUMENT_TYPE"; | ||
| /** Unsupported argument type (e.g. `{foo,foo}`) */ | ||
| ErrorKind[ErrorKind["INVALID_ARGUMENT_TYPE"] = 5] = "INVALID_ARGUMENT_TYPE"; | ||
| /** Expect an argument style (e.g. `{foo, number, }`) */ | ||
| ErrorKind[ErrorKind["EXPECT_ARGUMENT_STYLE"] = 6] = "EXPECT_ARGUMENT_STYLE"; | ||
| /** The number skeleton is invalid. */ | ||
| ErrorKind[ErrorKind["INVALID_NUMBER_SKELETON"] = 7] = "INVALID_NUMBER_SKELETON"; | ||
| /** The date time skeleton is invalid. */ | ||
| ErrorKind[ErrorKind["INVALID_DATE_TIME_SKELETON"] = 8] = "INVALID_DATE_TIME_SKELETON"; | ||
| /** Exepct a number skeleton following the `::` (e.g. `{foo, number, ::}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_NUMBER_SKELETON"] = 9] = "EXPECT_NUMBER_SKELETON"; | ||
| /** Exepct a date time skeleton following the `::` (e.g. `{foo, date, ::}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_DATE_TIME_SKELETON"] = 10] = "EXPECT_DATE_TIME_SKELETON"; | ||
| /** Unmatched apostrophes in the argument style (e.g. `{foo, number, 'test`) */ | ||
| ErrorKind[ErrorKind["UNCLOSED_QUOTE_IN_ARGUMENT_STYLE"] = 11] = "UNCLOSED_QUOTE_IN_ARGUMENT_STYLE"; | ||
| /** Missing select argument options (e.g. `{foo, select}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_OPTIONS"] = 12] = "EXPECT_SELECT_ARGUMENT_OPTIONS"; | ||
| /** Expecting an offset value in `plural` or `selectordinal` argument (e.g `{foo, plural, offset}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE"] = 13] = "EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE"; | ||
| /** Offset value in `plural` or `selectordinal` is invalid (e.g. `{foo, plural, offset: x}`) */ | ||
| ErrorKind[ErrorKind["INVALID_PLURAL_ARGUMENT_OFFSET_VALUE"] = 14] = "INVALID_PLURAL_ARGUMENT_OFFSET_VALUE"; | ||
| /** Expecting a selector in `select` argument (e.g `{foo, select}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_SELECTOR"] = 15] = "EXPECT_SELECT_ARGUMENT_SELECTOR"; | ||
| /** Expecting a selector in `plural` or `selectordinal` argument (e.g `{foo, plural}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_SELECTOR"] = 16] = "EXPECT_PLURAL_ARGUMENT_SELECTOR"; | ||
| /** Expecting a message fragment after the `select` selector (e.g. `{foo, select, apple}`) */ | ||
| ErrorKind[ErrorKind["EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT"] = 17] = "EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT"; | ||
| /** | ||
| * Expecting a message fragment after the `plural` or `selectordinal` selector | ||
| * (e.g. `{foo, plural, one}`) | ||
| */ | ||
| ErrorKind[ErrorKind["EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT"] = 18] = "EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT"; | ||
| /** Selector in `plural` or `selectordinal` is malformed (e.g. `{foo, plural, =x {#}}`) */ | ||
| ErrorKind[ErrorKind["INVALID_PLURAL_ARGUMENT_SELECTOR"] = 19] = "INVALID_PLURAL_ARGUMENT_SELECTOR"; | ||
| /** | ||
| * Duplicate selectors in `plural` or `selectordinal` argument. | ||
| * (e.g. {foo, plural, one {#} one {#}}) | ||
| */ | ||
| ErrorKind[ErrorKind["DUPLICATE_PLURAL_ARGUMENT_SELECTOR"] = 20] = "DUPLICATE_PLURAL_ARGUMENT_SELECTOR"; | ||
| /** Duplicate selectors in `select` argument. | ||
| * (e.g. {foo, select, apple {apple} apple {apple}}) | ||
| */ | ||
| ErrorKind[ErrorKind["DUPLICATE_SELECT_ARGUMENT_SELECTOR"] = 21] = "DUPLICATE_SELECT_ARGUMENT_SELECTOR"; | ||
| /** Plural or select argument option must have `other` clause. */ | ||
| ErrorKind[ErrorKind["MISSING_OTHER_CLAUSE"] = 22] = "MISSING_OTHER_CLAUSE"; | ||
| /** The tag is malformed. (e.g. `<bold!>foo</bold!>) */ | ||
| ErrorKind[ErrorKind["INVALID_TAG"] = 23] = "INVALID_TAG"; | ||
| /** The tag name is invalid. (e.g. `<123>foo</123>`) */ | ||
| ErrorKind[ErrorKind["INVALID_TAG_NAME"] = 25] = "INVALID_TAG_NAME"; | ||
| /** The closing tag does not match the opening tag. (e.g. `<bold>foo</italic>`) */ | ||
| ErrorKind[ErrorKind["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG"; | ||
| /** The opening tag has unmatched closing tag. (e.g. `<bold>foo`) */ | ||
| ErrorKind[ErrorKind["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG"; | ||
| })(ErrorKind || (ErrorKind = {})); |
| import { Parser, ParserOptions } from './parser'; | ||
| import { MessageFormatElement } from './types'; | ||
| export declare function parse(message: string, opts?: ParserOptions): MessageFormatElement[]; | ||
| export * from './types'; | ||
| export type { ParserOptions }; | ||
| export declare const _Parser: typeof Parser; | ||
| export { isStructurallySame } from './manipulator'; |
-46
| import { __assign } from "tslib"; | ||
| import { ErrorKind } from './error'; | ||
| import { Parser } from './parser'; | ||
| import { isDateElement, isDateTimeSkeleton, isNumberElement, isNumberSkeleton, isPluralElement, isSelectElement, isTagElement, isTimeElement, } from './types'; | ||
| function pruneLocation(els) { | ||
| els.forEach(function (el) { | ||
| delete el.location; | ||
| if (isSelectElement(el) || isPluralElement(el)) { | ||
| for (var k in el.options) { | ||
| delete el.options[k].location; | ||
| pruneLocation(el.options[k].value); | ||
| } | ||
| } | ||
| else if (isNumberElement(el) && isNumberSkeleton(el.style)) { | ||
| delete el.style.location; | ||
| } | ||
| else if ((isDateElement(el) || isTimeElement(el)) && | ||
| isDateTimeSkeleton(el.style)) { | ||
| delete el.style.location; | ||
| } | ||
| else if (isTagElement(el)) { | ||
| pruneLocation(el.children); | ||
| } | ||
| }); | ||
| } | ||
| export function parse(message, opts) { | ||
| if (opts === void 0) { opts = {}; } | ||
| opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts); | ||
| var result = new Parser(message, opts).parse(); | ||
| if (result.err) { | ||
| var error = SyntaxError(ErrorKind[result.err.kind]); | ||
| // @ts-expect-error Assign to error object | ||
| error.location = result.err.location; | ||
| // @ts-expect-error Assign to error object | ||
| error.originalMessage = result.err.message; | ||
| throw error; | ||
| } | ||
| if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) { | ||
| pruneLocation(result.val); | ||
| } | ||
| return result.val; | ||
| } | ||
| export * from './types'; | ||
| // only for testing | ||
| export var _Parser = Parser; | ||
| export { isStructurallySame } from './manipulator'; |
| import { MessageFormatElement } from './types'; | ||
| /** | ||
| * Hoist all selectors to the beginning of the AST & flatten the | ||
| * resulting options. E.g: | ||
| * "I have {count, plural, one{a dog} other{many dogs}}" | ||
| * becomes "{count, plural, one{I have a dog} other{I have many dogs}}". | ||
| * If there are multiple selectors, the order of which one is hoisted 1st | ||
| * is non-deterministic. | ||
| * The goal is to provide as many full sentences as possible since fragmented | ||
| * sentences are not translator-friendly | ||
| * @param ast AST | ||
| */ | ||
| export declare function hoistSelectors(ast: MessageFormatElement[]): MessageFormatElement[]; | ||
| interface IsStructurallySameResult { | ||
| error?: Error; | ||
| success: boolean; | ||
| } | ||
| /** | ||
| * Check if 2 ASTs are structurally the same. This primarily means that | ||
| * they have the same variables with the same type | ||
| * @param a | ||
| * @param b | ||
| * @returns | ||
| */ | ||
| export declare function isStructurallySame(a: MessageFormatElement[], b: MessageFormatElement[]): IsStructurallySameResult; | ||
| export {}; |
| import { __spreadArray } from "tslib"; | ||
| import { isArgumentElement, isDateElement, isNumberElement, isPluralElement, isSelectElement, isTagElement, isTimeElement, TYPE, } from './types'; | ||
| function cloneDeep(obj) { | ||
| if (Array.isArray(obj)) { | ||
| // @ts-expect-error meh | ||
| return __spreadArray([], obj.map(cloneDeep), true); | ||
| } | ||
| if (obj !== null && typeof obj === 'object') { | ||
| // @ts-expect-error meh | ||
| return Object.keys(obj).reduce(function (cloned, k) { | ||
| // @ts-expect-error meh | ||
| cloned[k] = cloneDeep(obj[k]); | ||
| return cloned; | ||
| }, {}); | ||
| } | ||
| return obj; | ||
| } | ||
| function hoistPluralOrSelectElement(ast, el, positionToInject) { | ||
| // pull this out of the ast and move it to the top | ||
| var cloned = cloneDeep(el); | ||
| var options = cloned.options; | ||
| 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)); | ||
| all[k] = { | ||
| value: newValue, | ||
| }; | ||
| return all; | ||
| }, {}); | ||
| return cloned; | ||
| } | ||
| function isPluralOrSelectElement(el) { | ||
| return isPluralElement(el) || isSelectElement(el); | ||
| } | ||
| function findPluralOrSelectElement(ast) { | ||
| return !!ast.find(function (el) { | ||
| if (isPluralOrSelectElement(el)) { | ||
| return true; | ||
| } | ||
| if (isTagElement(el)) { | ||
| return findPluralOrSelectElement(el.children); | ||
| } | ||
| return false; | ||
| }); | ||
| } | ||
| /** | ||
| * Hoist all selectors to the beginning of the AST & flatten the | ||
| * resulting options. E.g: | ||
| * "I have {count, plural, one{a dog} other{many dogs}}" | ||
| * becomes "{count, plural, one{I have a dog} other{I have many dogs}}". | ||
| * If there are multiple selectors, the order of which one is hoisted 1st | ||
| * is non-deterministic. | ||
| * The goal is to provide as many full sentences as possible since fragmented | ||
| * sentences are not translator-friendly | ||
| * @param ast AST | ||
| */ | ||
| export function hoistSelectors(ast) { | ||
| for (var i = 0; i < ast.length; i++) { | ||
| var el = ast[i]; | ||
| if (isPluralOrSelectElement(el)) { | ||
| return [hoistPluralOrSelectElement(ast, el, i)]; | ||
| } | ||
| if (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'); | ||
| } | ||
| } | ||
| return ast; | ||
| } | ||
| /** | ||
| * Collect all variables in an AST to Record<string, TYPE> | ||
| * @param ast AST to collect variables from | ||
| * @param vars Record of variable name to variable type | ||
| */ | ||
| function collectVariables(ast, vars) { | ||
| if (vars === void 0) { vars = new Map(); } | ||
| ast.forEach(function (el) { | ||
| if (isArgumentElement(el) || | ||
| isDateElement(el) || | ||
| isTimeElement(el) || | ||
| isNumberElement(el)) { | ||
| if (el.value in vars && vars.get(el.value) !== el.type) { | ||
| throw new Error("Variable ".concat(el.value, " has conflicting types")); | ||
| } | ||
| vars.set(el.value, el.type); | ||
| } | ||
| if (isPluralElement(el) || isSelectElement(el)) { | ||
| vars.set(el.value, el.type); | ||
| Object.keys(el.options).forEach(function (k) { | ||
| collectVariables(el.options[k].value, vars); | ||
| }); | ||
| } | ||
| if (isTagElement(el)) { | ||
| vars.set(el.value, el.type); | ||
| collectVariables(el.children, vars); | ||
| } | ||
| }); | ||
| } | ||
| /** | ||
| * Check if 2 ASTs are structurally the same. This primarily means that | ||
| * they have the same variables with the same type | ||
| * @param a | ||
| * @param b | ||
| * @returns | ||
| */ | ||
| export function isStructurallySame(a, b) { | ||
| var aVars = new Map(); | ||
| var bVars = new Map(); | ||
| collectVariables(a, aVars); | ||
| collectVariables(b, bVars); | ||
| if (aVars.size !== bVars.size) { | ||
| return { | ||
| success: false, | ||
| error: new Error("Different number of variables: [".concat(Array.from(aVars.keys()).join(', '), "] vs [").concat(Array.from(bVars.keys()).join(', '), "]")), | ||
| }; | ||
| } | ||
| return Array.from(aVars.entries()).reduce(function (result, _a) { | ||
| var key = _a[0], type = _a[1]; | ||
| if (!result.success) { | ||
| return result; | ||
| } | ||
| var bType = bVars.get(key); | ||
| if (bType == null) { | ||
| return { | ||
| success: false, | ||
| error: new Error("Missing variable ".concat(key, " in message")), | ||
| }; | ||
| } | ||
| if (bType !== type) { | ||
| return { | ||
| success: false, | ||
| error: new Error("Variable ".concat(key, " has conflicting types: ").concat(TYPE[type], " vs ").concat(TYPE[bType])), | ||
| }; | ||
| } | ||
| return result; | ||
| }, { success: true }); | ||
| } |
| export declare function parse(): void; | ||
| export * from './types'; | ||
| export declare const _Parser: undefined; | ||
| export { isStructurallySame } from './manipulator'; |
| export 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; | ||
| export { isStructurallySame } from './manipulator'; |
-147
| import { ParserError } from './error'; | ||
| import { MessageFormatElement } from './types'; | ||
| export interface Position { | ||
| /** Offset in terms of UTF-16 *code unit*. */ | ||
| offset: number; | ||
| line: number; | ||
| /** Column offset in terms of unicode *code point*. */ | ||
| column: number; | ||
| } | ||
| export interface ParserOptions { | ||
| /** | ||
| * Whether to treat HTML/XML tags as string literal | ||
| * instead of parsing them as tag token. | ||
| * When this is false we only allow simple tags without | ||
| * any attributes | ||
| */ | ||
| ignoreTag?: boolean; | ||
| /** | ||
| * Should `select`, `selectordinal`, and `plural` arguments always include | ||
| * the `other` case clause. | ||
| */ | ||
| requiresOtherClause?: boolean; | ||
| /** | ||
| * Whether to parse number/datetime skeleton | ||
| * into Intl.NumberFormatOptions and Intl.DateTimeFormatOptions, respectively. | ||
| */ | ||
| shouldParseSkeletons?: boolean; | ||
| /** | ||
| * Capture location info in AST | ||
| * Default is false | ||
| */ | ||
| captureLocation?: boolean; | ||
| /** | ||
| * Instance of Intl.Locale to resolve locale-dependent skeleton | ||
| */ | ||
| locale?: Intl.Locale; | ||
| } | ||
| export type Result<T, E> = { | ||
| val: T; | ||
| err: null; | ||
| } | { | ||
| val: null; | ||
| err: E; | ||
| }; | ||
| export declare class Parser { | ||
| private message; | ||
| private position; | ||
| private locale?; | ||
| private ignoreTag; | ||
| private requiresOtherClause; | ||
| private shouldParseSkeletons?; | ||
| constructor(message: string, options?: ParserOptions); | ||
| parse(): Result<MessageFormatElement[], ParserError>; | ||
| private parseMessage; | ||
| /** | ||
| * A tag name must start with an ASCII lower/upper case letter. The grammar is based on the | ||
| * [custom element name][] except that a dash is NOT always mandatory and uppercase letters | ||
| * are accepted: | ||
| * | ||
| * ``` | ||
| * tag ::= "<" tagName (whitespace)* "/>" | "<" tagName (whitespace)* ">" message "</" tagName (whitespace)* ">" | ||
| * tagName ::= [a-z] (PENChar)* | ||
| * PENChar ::= | ||
| * "-" | "." | [0-9] | "_" | [a-z] | [A-Z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | | ||
| * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | | ||
| * [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
| * ``` | ||
| * | ||
| * [custom element name]: https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
| * NOTE: We're a bit more lax here since HTML technically does not allow uppercase HTML element but we do | ||
| * since other tag-based engines like React allow it | ||
| */ | ||
| private parseTag; | ||
| /** | ||
| * This method assumes that the caller has peeked ahead for the first tag character. | ||
| */ | ||
| private parseTagName; | ||
| private parseLiteral; | ||
| tryParseLeftAngleBracket(): string | null; | ||
| /** | ||
| * Starting with ICU 4.8, an ASCII apostrophe only starts quoted text if it immediately precedes | ||
| * a character that requires quoting (that is, "only where needed"), and works the same in | ||
| * nested messages as on the top level of the pattern. The new behavior is otherwise compatible. | ||
| */ | ||
| private tryParseQuote; | ||
| private tryParseUnquoted; | ||
| private parseArgument; | ||
| /** | ||
| * Advance the parser until the end of the identifier, if it is currently on | ||
| * an identifier character. Return an empty string otherwise. | ||
| */ | ||
| private parseIdentifierIfPossible; | ||
| private parseArgumentOptions; | ||
| private tryParseArgumentClose; | ||
| /** | ||
| * See: https://github.com/unicode-org/icu/blob/af7ed1f6d2298013dc303628438ec4abe1f16479/icu4c/source/common/messagepattern.cpp#L659 | ||
| */ | ||
| private parseSimpleArgStyleIfPossible; | ||
| private parseNumberSkeletonFromString; | ||
| /** | ||
| * @param nesting_level The current nesting level of messages. | ||
| * This can be positive when parsing message fragment in select or plural argument options. | ||
| * @param parent_arg_type The parent argument's type. | ||
| * @param parsed_first_identifier If provided, this is the first identifier-like selector of | ||
| * the argument. It is a by-product of a previous parsing attempt. | ||
| * @param expecting_close_tag If true, this message is directly or indirectly nested inside | ||
| * between a pair of opening and closing tags. The nested message will not parse beyond | ||
| * the closing tag boundary. | ||
| */ | ||
| private tryParsePluralOrSelectOptions; | ||
| private tryParseDecimalInteger; | ||
| private offset; | ||
| private isEOF; | ||
| private clonePosition; | ||
| /** | ||
| * Return the code point at the current position of the parser. | ||
| * Throws if the index is out of bound. | ||
| */ | ||
| private char; | ||
| private error; | ||
| /** Bump the parser to the next UTF-16 code unit. */ | ||
| private bump; | ||
| /** | ||
| * If the substring starting at the current position of the parser has | ||
| * the given prefix, then bump the parser to the character immediately | ||
| * following the prefix and return true. Otherwise, don't bump the parser | ||
| * and return false. | ||
| */ | ||
| private bumpIf; | ||
| /** | ||
| * Bump the parser until the pattern character is found and return `true`. | ||
| * Otherwise bump to the end of the file and return `false`. | ||
| */ | ||
| private bumpUntil; | ||
| /** | ||
| * Bump the parser to the target offset. | ||
| * If target offset is beyond the end of the input, bump the parser to the end of the input. | ||
| */ | ||
| private bumpTo; | ||
| /** advance the parser through all whitespace to the next non-whitespace code unit. */ | ||
| private bumpSpace; | ||
| /** | ||
| * Peek at the *next* Unicode codepoint in the input without advancing the parser. | ||
| * If the input has been exhausted, then this returns null. | ||
| */ | ||
| private peek; | ||
| } |
-1276
| 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, "*$")); | ||
| function createLocation(start, end) { | ||
| return { start: start, end: end }; | ||
| } | ||
| // #region Ponyfills | ||
| // Consolidate these variables up top for easier toggling during debugging | ||
| var hasNativeStartsWith = !!String.prototype.startsWith && '_a'.startsWith('a', 1); | ||
| var hasNativeFromCodePoint = !!String.fromCodePoint; | ||
| var hasNativeFromEntries = !!Object.fromEntries; | ||
| var hasNativeCodePointAt = !!String.prototype.codePointAt; | ||
| var hasTrimStart = !!String.prototype.trimStart; | ||
| var hasTrimEnd = !!String.prototype.trimEnd; | ||
| var hasNativeIsSafeInteger = !!Number.isSafeInteger; | ||
| var isSafeInteger = hasNativeIsSafeInteger | ||
| ? Number.isSafeInteger | ||
| : function (n) { | ||
| return (typeof n === 'number' && | ||
| isFinite(n) && | ||
| Math.floor(n) === n && | ||
| Math.abs(n) <= 0x1fffffffffffff); | ||
| }; | ||
| // IE11 does not support y and u. | ||
| var REGEX_SUPPORTS_U_AND_Y = true; | ||
| try { | ||
| var re = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu'); | ||
| /** | ||
| * legacy Edge or Xbox One browser | ||
| * Unicode flag support: supported | ||
| * Pattern_Syntax support: not supported | ||
| * See https://github.com/formatjs/formatjs/issues/2822 | ||
| */ | ||
| REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec('a')) === null || _a === void 0 ? void 0 : _a[0]) === 'a'; | ||
| } | ||
| catch (_) { | ||
| REGEX_SUPPORTS_U_AND_Y = false; | ||
| } | ||
| var startsWith = hasNativeStartsWith | ||
| ? // Native | ||
| function startsWith(s, search, position) { | ||
| return s.startsWith(search, position); | ||
| } | ||
| : // For IE11 | ||
| function startsWith(s, search, position) { | ||
| return s.slice(position, position + search.length) === search; | ||
| }; | ||
| var fromCodePoint = hasNativeFromCodePoint | ||
| ? String.fromCodePoint | ||
| : // IE11 | ||
| function fromCodePoint() { | ||
| var codePoints = []; | ||
| for (var _i = 0; _i < arguments.length; _i++) { | ||
| codePoints[_i] = arguments[_i]; | ||
| } | ||
| var elements = ''; | ||
| var length = codePoints.length; | ||
| var i = 0; | ||
| var code; | ||
| while (length > i) { | ||
| code = codePoints[i++]; | ||
| if (code > 0x10ffff) | ||
| throw RangeError(code + ' is not a valid code point'); | ||
| elements += | ||
| code < 0x10000 | ||
| ? String.fromCharCode(code) | ||
| : String.fromCharCode(((code -= 0x10000) >> 10) + 0xd800, (code % 0x400) + 0xdc00); | ||
| } | ||
| return elements; | ||
| }; | ||
| var fromEntries = | ||
| // native | ||
| hasNativeFromEntries | ||
| ? Object.fromEntries | ||
| : // Ponyfill | ||
| function fromEntries(entries) { | ||
| var obj = {}; | ||
| for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) { | ||
| var _a = entries_1[_i], k = _a[0], v = _a[1]; | ||
| obj[k] = v; | ||
| } | ||
| return obj; | ||
| }; | ||
| var codePointAt = hasNativeCodePointAt | ||
| ? // Native | ||
| function codePointAt(s, index) { | ||
| return s.codePointAt(index); | ||
| } | ||
| : // IE 11 | ||
| function codePointAt(s, index) { | ||
| var size = s.length; | ||
| if (index < 0 || index >= size) { | ||
| return undefined; | ||
| } | ||
| var first = s.charCodeAt(index); | ||
| var second; | ||
| return first < 0xd800 || | ||
| first > 0xdbff || | ||
| index + 1 === size || | ||
| (second = s.charCodeAt(index + 1)) < 0xdc00 || | ||
| second > 0xdfff | ||
| ? first | ||
| : ((first - 0xd800) << 10) + (second - 0xdc00) + 0x10000; | ||
| }; | ||
| var trimStart = hasTrimStart | ||
| ? // Native | ||
| function trimStart(s) { | ||
| return s.trimStart(); | ||
| } | ||
| : // Ponyfill | ||
| function trimStart(s) { | ||
| return s.replace(SPACE_SEPARATOR_START_REGEX, ''); | ||
| }; | ||
| var trimEnd = hasTrimEnd | ||
| ? // Native | ||
| function trimEnd(s) { | ||
| return s.trimEnd(); | ||
| } | ||
| : // Ponyfill | ||
| function trimEnd(s) { | ||
| return s.replace(SPACE_SEPARATOR_END_REGEX, ''); | ||
| }; | ||
| // Prevent minifier to translate new RegExp to literal form that might cause syntax error on IE11. | ||
| function RE(s, flag) { | ||
| return new RegExp(s, flag); | ||
| } | ||
| // #endregion | ||
| var matchIdentifierAtIndex; | ||
| if (REGEX_SUPPORTS_U_AND_Y) { | ||
| // Native | ||
| var IDENTIFIER_PREFIX_RE_1 = RE('([^\\p{White_Space}\\p{Pattern_Syntax}]*)', 'yu'); | ||
| matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) { | ||
| var _a; | ||
| IDENTIFIER_PREFIX_RE_1.lastIndex = index; | ||
| var match = IDENTIFIER_PREFIX_RE_1.exec(s); | ||
| return (_a = match[1]) !== null && _a !== void 0 ? _a : ''; | ||
| }; | ||
| } | ||
| else { | ||
| // IE11 | ||
| matchIdentifierAtIndex = function matchIdentifierAtIndex(s, index) { | ||
| var match = []; | ||
| while (true) { | ||
| var c = codePointAt(s, index); | ||
| if (c === undefined || _isWhiteSpace(c) || _isPatternSyntax(c)) { | ||
| break; | ||
| } | ||
| match.push(c); | ||
| index += c >= 0x10000 ? 2 : 1; | ||
| } | ||
| return fromCodePoint.apply(void 0, match); | ||
| }; | ||
| } | ||
| var Parser = /** @class */ (function () { | ||
| function Parser(message, options) { | ||
| if (options === void 0) { options = {}; } | ||
| this.message = message; | ||
| this.position = { offset: 0, line: 1, column: 1 }; | ||
| this.ignoreTag = !!options.ignoreTag; | ||
| this.locale = options.locale; | ||
| this.requiresOtherClause = !!options.requiresOtherClause; | ||
| this.shouldParseSkeletons = !!options.shouldParseSkeletons; | ||
| } | ||
| Parser.prototype.parse = function () { | ||
| if (this.offset() !== 0) { | ||
| throw Error('parser can only be used once'); | ||
| } | ||
| return this.parseMessage(0, '', false); | ||
| }; | ||
| Parser.prototype.parseMessage = function (nestingLevel, parentArgType, expectingCloseTag) { | ||
| var elements = []; | ||
| while (!this.isEOF()) { | ||
| var char = this.char(); | ||
| if (char === 123 /* `{` */) { | ||
| var result = this.parseArgument(nestingLevel, expectingCloseTag); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| elements.push(result.val); | ||
| } | ||
| else if (char === 125 /* `}` */ && nestingLevel > 0) { | ||
| break; | ||
| } | ||
| else if (char === 35 /* `#` */ && | ||
| (parentArgType === 'plural' || parentArgType === 'selectordinal')) { | ||
| var position = this.clonePosition(); | ||
| this.bump(); | ||
| elements.push({ | ||
| type: TYPE.pound, | ||
| location: createLocation(position, this.clonePosition()), | ||
| }); | ||
| } | ||
| else if (char === 60 /* `<` */ && | ||
| !this.ignoreTag && | ||
| this.peek() === 47 // char code for '/' | ||
| ) { | ||
| if (expectingCloseTag) { | ||
| break; | ||
| } | ||
| else { | ||
| return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
| } | ||
| else if (char === 60 /* `<` */ && | ||
| !this.ignoreTag && | ||
| _isAlpha(this.peek() || 0)) { | ||
| var result = this.parseTag(nestingLevel, parentArgType); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| elements.push(result.val); | ||
| } | ||
| else { | ||
| var result = this.parseLiteral(nestingLevel, parentArgType); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| elements.push(result.val); | ||
| } | ||
| } | ||
| return { val: elements, err: null }; | ||
| }; | ||
| /** | ||
| * A tag name must start with an ASCII lower/upper case letter. The grammar is based on the | ||
| * [custom element name][] except that a dash is NOT always mandatory and uppercase letters | ||
| * are accepted: | ||
| * | ||
| * ``` | ||
| * tag ::= "<" tagName (whitespace)* "/>" | "<" tagName (whitespace)* ">" message "</" tagName (whitespace)* ">" | ||
| * tagName ::= [a-z] (PENChar)* | ||
| * PENChar ::= | ||
| * "-" | "." | [0-9] | "_" | [a-z] | [A-Z] | #xB7 | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x37D] | | ||
| * [#x37F-#x1FFF] | [#x200C-#x200D] | [#x203F-#x2040] | [#x2070-#x218F] | [#x2C00-#x2FEF] | | ||
| * [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF] | ||
| * ``` | ||
| * | ||
| * [custom element name]: https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name | ||
| * NOTE: We're a bit more lax here since HTML technically does not allow uppercase HTML element but we do | ||
| * since other tag-based engines like React allow it | ||
| */ | ||
| Parser.prototype.parseTag = function (nestingLevel, parentArgType) { | ||
| var startPosition = this.clonePosition(); | ||
| this.bump(); // `<` | ||
| var tagName = this.parseTagName(); | ||
| this.bumpSpace(); | ||
| if (this.bumpIf('/>')) { | ||
| // Self closing tag | ||
| return { | ||
| val: { | ||
| type: TYPE.literal, | ||
| value: "<".concat(tagName, "/>"), | ||
| location: createLocation(startPosition, this.clonePosition()), | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| else if (this.bumpIf('>')) { | ||
| var childrenResult = this.parseMessage(nestingLevel + 1, parentArgType, true); | ||
| if (childrenResult.err) { | ||
| return childrenResult; | ||
| } | ||
| var children = childrenResult.val; | ||
| // Expecting a close tag | ||
| var endTagStartPosition = this.clonePosition(); | ||
| if (this.bumpIf('</')) { | ||
| if (this.isEOF() || !_isAlpha(this.char())) { | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| } | ||
| var closingTagNameStartPosition = this.clonePosition(); | ||
| var closingTagName = this.parseTagName(); | ||
| if (tagName !== closingTagName) { | ||
| return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition())); | ||
| } | ||
| this.bumpSpace(); | ||
| if (!this.bumpIf('>')) { | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition())); | ||
| } | ||
| return { | ||
| val: { | ||
| type: TYPE.tag, | ||
| value: tagName, | ||
| children: children, | ||
| location: createLocation(startPosition, this.clonePosition()), | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| else { | ||
| return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition())); | ||
| } | ||
| } | ||
| else { | ||
| return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition())); | ||
| } | ||
| }; | ||
| /** | ||
| * This method assumes that the caller has peeked ahead for the first tag character. | ||
| */ | ||
| Parser.prototype.parseTagName = function () { | ||
| var startOffset = this.offset(); | ||
| this.bump(); // the first tag name character | ||
| while (!this.isEOF() && _isPotentialElementNameChar(this.char())) { | ||
| this.bump(); | ||
| } | ||
| return this.message.slice(startOffset, this.offset()); | ||
| }; | ||
| Parser.prototype.parseLiteral = function (nestingLevel, parentArgType) { | ||
| var start = this.clonePosition(); | ||
| var value = ''; | ||
| while (true) { | ||
| var parseQuoteResult = this.tryParseQuote(parentArgType); | ||
| if (parseQuoteResult) { | ||
| value += parseQuoteResult; | ||
| continue; | ||
| } | ||
| var parseUnquotedResult = this.tryParseUnquoted(nestingLevel, parentArgType); | ||
| if (parseUnquotedResult) { | ||
| value += parseUnquotedResult; | ||
| continue; | ||
| } | ||
| var parseLeftAngleResult = this.tryParseLeftAngleBracket(); | ||
| if (parseLeftAngleResult) { | ||
| value += parseLeftAngleResult; | ||
| continue; | ||
| } | ||
| break; | ||
| } | ||
| var location = createLocation(start, this.clonePosition()); | ||
| return { | ||
| val: { type: TYPE.literal, value: value, location: location }, | ||
| err: null, | ||
| }; | ||
| }; | ||
| Parser.prototype.tryParseLeftAngleBracket = function () { | ||
| if (!this.isEOF() && | ||
| this.char() === 60 /* `<` */ && | ||
| (this.ignoreTag || | ||
| // If at the opening tag or closing tag position, bail. | ||
| !_isAlphaOrSlash(this.peek() || 0))) { | ||
| this.bump(); // `<` | ||
| return '<'; | ||
| } | ||
| return null; | ||
| }; | ||
| /** | ||
| * Starting with ICU 4.8, an ASCII apostrophe only starts quoted text if it immediately precedes | ||
| * a character that requires quoting (that is, "only where needed"), and works the same in | ||
| * nested messages as on the top level of the pattern. The new behavior is otherwise compatible. | ||
| */ | ||
| Parser.prototype.tryParseQuote = function (parentArgType) { | ||
| if (this.isEOF() || this.char() !== 39 /* `'` */) { | ||
| return null; | ||
| } | ||
| // Parse escaped char following the apostrophe, or early return if there is no escaped char. | ||
| // Check if is valid escaped character | ||
| switch (this.peek()) { | ||
| case 39 /* `'` */: | ||
| // double quote, should return as a single quote. | ||
| this.bump(); | ||
| this.bump(); | ||
| return "'"; | ||
| // '{', '<', '>', '}' | ||
| case 123: | ||
| case 60: | ||
| case 62: | ||
| case 125: | ||
| break; | ||
| case 35: // '#' | ||
| if (parentArgType === 'plural' || parentArgType === 'selectordinal') { | ||
| break; | ||
| } | ||
| return null; | ||
| default: | ||
| return null; | ||
| } | ||
| this.bump(); // apostrophe | ||
| var codePoints = [this.char()]; // escaped char | ||
| this.bump(); | ||
| // read chars until the optional closing apostrophe is found | ||
| while (!this.isEOF()) { | ||
| var ch = this.char(); | ||
| if (ch === 39 /* `'` */) { | ||
| if (this.peek() === 39 /* `'` */) { | ||
| codePoints.push(39); | ||
| // Bump one more time because we need to skip 2 characters. | ||
| this.bump(); | ||
| } | ||
| else { | ||
| // Optional closing apostrophe. | ||
| this.bump(); | ||
| break; | ||
| } | ||
| } | ||
| else { | ||
| codePoints.push(ch); | ||
| } | ||
| this.bump(); | ||
| } | ||
| return fromCodePoint.apply(void 0, codePoints); | ||
| }; | ||
| Parser.prototype.tryParseUnquoted = function (nestingLevel, parentArgType) { | ||
| if (this.isEOF()) { | ||
| return null; | ||
| } | ||
| var ch = this.char(); | ||
| if (ch === 60 /* `<` */ || | ||
| ch === 123 /* `{` */ || | ||
| (ch === 35 /* `#` */ && | ||
| (parentArgType === 'plural' || parentArgType === 'selectordinal')) || | ||
| (ch === 125 /* `}` */ && nestingLevel > 0)) { | ||
| return null; | ||
| } | ||
| else { | ||
| this.bump(); | ||
| return fromCodePoint(ch); | ||
| } | ||
| }; | ||
| Parser.prototype.parseArgument = function (nestingLevel, expectingCloseTag) { | ||
| var openingBracePosition = this.clonePosition(); | ||
| this.bump(); // `{` | ||
| this.bumpSpace(); | ||
| if (this.isEOF()) { | ||
| return this.error(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())); | ||
| } | ||
| // argument name | ||
| var value = this.parseIdentifierIfPossible().value; | ||
| if (!value) { | ||
| return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| this.bumpSpace(); | ||
| if (this.isEOF()) { | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| switch (this.char()) { | ||
| // Simple argument: `{name}` | ||
| case 125 /* `}` */: { | ||
| this.bump(); // `}` | ||
| return { | ||
| val: { | ||
| type: TYPE.argument, | ||
| // value does not include the opening and closing braces. | ||
| value: value, | ||
| location: createLocation(openingBracePosition, this.clonePosition()), | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| // Argument with options: `{name, format, ...}` | ||
| case 44 /* `,` */: { | ||
| this.bump(); // `,` | ||
| this.bumpSpace(); | ||
| if (this.isEOF()) { | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition); | ||
| } | ||
| default: | ||
| return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| }; | ||
| /** | ||
| * Advance the parser until the end of the identifier, if it is currently on | ||
| * an identifier character. Return an empty string otherwise. | ||
| */ | ||
| Parser.prototype.parseIdentifierIfPossible = function () { | ||
| var startingPosition = this.clonePosition(); | ||
| var startOffset = this.offset(); | ||
| var value = matchIdentifierAtIndex(this.message, startOffset); | ||
| var endOffset = startOffset + value.length; | ||
| this.bumpTo(endOffset); | ||
| var endPosition = this.clonePosition(); | ||
| var location = createLocation(startingPosition, endPosition); | ||
| return { value: value, location: location }; | ||
| }; | ||
| Parser.prototype.parseArgumentOptions = function (nestingLevel, expectingCloseTag, value, openingBracePosition) { | ||
| var _a; | ||
| // Parse this range: | ||
| // {name, type, style} | ||
| // ^---^ | ||
| var typeStartPosition = this.clonePosition(); | ||
| var argType = this.parseIdentifierIfPossible().value; | ||
| var typeEndPosition = this.clonePosition(); | ||
| switch (argType) { | ||
| case '': | ||
| // Expecting a style string number, date, time, plural, selectordinal, or select. | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| case 'number': | ||
| case 'date': | ||
| case 'time': { | ||
| // Parse this range: | ||
| // {name, number, style} | ||
| // ^-------^ | ||
| this.bumpSpace(); | ||
| var styleAndLocation = null; | ||
| if (this.bumpIf(',')) { | ||
| this.bumpSpace(); | ||
| var styleStartPosition = this.clonePosition(); | ||
| var result = this.parseSimpleArgStyleIfPossible(); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| var style = trimEnd(result.val); | ||
| if (style.length === 0) { | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
| var styleLocation = createLocation(styleStartPosition, this.clonePosition()); | ||
| styleAndLocation = { style: style, styleLocation: styleLocation }; | ||
| } | ||
| var argCloseResult = this.tryParseArgumentClose(openingBracePosition); | ||
| if (argCloseResult.err) { | ||
| return argCloseResult; | ||
| } | ||
| var location_1 = createLocation(openingBracePosition, this.clonePosition()); | ||
| // Extract style or skeleton | ||
| if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, '::', 0)) { | ||
| // Skeleton starts with `::`. | ||
| var skeleton = trimStart(styleAndLocation.style.slice(2)); | ||
| if (argType === 'number') { | ||
| var result = this.parseNumberSkeletonFromString(skeleton, styleAndLocation.styleLocation); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| return { | ||
| val: { type: TYPE.number, value: value, location: location_1, style: result.val }, | ||
| err: null, | ||
| }; | ||
| } | ||
| else { | ||
| if (skeleton.length === 0) { | ||
| return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1); | ||
| } | ||
| var dateTimePattern = skeleton; | ||
| // Get "best match" pattern only if locale is passed, if not, let it | ||
| // pass as-is where `parseDateTimeSkeleton()` will throw an error | ||
| // for unsupported patterns. | ||
| if (this.locale) { | ||
| dateTimePattern = getBestPattern(skeleton, this.locale); | ||
| } | ||
| var style = { | ||
| type: SKELETON_TYPE.dateTime, | ||
| pattern: dateTimePattern, | ||
| location: styleAndLocation.styleLocation, | ||
| parsedOptions: this.shouldParseSkeletons | ||
| ? parseDateTimeSkeleton(dateTimePattern) | ||
| : {}, | ||
| }; | ||
| var type = argType === 'date' ? TYPE.date : TYPE.time; | ||
| return { | ||
| val: { type: type, value: value, location: location_1, style: style }, | ||
| err: null, | ||
| }; | ||
| } | ||
| } | ||
| // Regular style or no style. | ||
| return { | ||
| val: { | ||
| type: argType === 'number' | ||
| ? TYPE.number | ||
| : argType === 'date' | ||
| ? TYPE.date | ||
| : TYPE.time, | ||
| value: value, | ||
| location: location_1, | ||
| style: (_a = styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style) !== null && _a !== void 0 ? _a : null, | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| case 'plural': | ||
| case 'selectordinal': | ||
| case 'select': { | ||
| // Parse this range: | ||
| // {name, plural, options} | ||
| // ^---------^ | ||
| var typeEndPosition_1 = this.clonePosition(); | ||
| this.bumpSpace(); | ||
| if (!this.bumpIf(',')) { | ||
| return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, __assign({}, typeEndPosition_1))); | ||
| } | ||
| this.bumpSpace(); | ||
| // Parse offset: | ||
| // {name, plural, offset:1, options} | ||
| // ^-----^ | ||
| // | ||
| // or the first option: | ||
| // | ||
| // {name, plural, one {...} other {...}} | ||
| // ^--^ | ||
| var identifierAndLocation = this.parseIdentifierIfPossible(); | ||
| var pluralOffset = 0; | ||
| if (argType !== 'select' && identifierAndLocation.value === 'offset') { | ||
| if (!this.bumpIf(':')) { | ||
| return this.error(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); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| // Parse another identifier for option parsing | ||
| this.bumpSpace(); | ||
| identifierAndLocation = this.parseIdentifierIfPossible(); | ||
| pluralOffset = result.val; | ||
| } | ||
| var optionsResult = this.tryParsePluralOrSelectOptions(nestingLevel, argType, expectingCloseTag, identifierAndLocation); | ||
| if (optionsResult.err) { | ||
| return optionsResult; | ||
| } | ||
| var argCloseResult = this.tryParseArgumentClose(openingBracePosition); | ||
| if (argCloseResult.err) { | ||
| return argCloseResult; | ||
| } | ||
| var location_2 = createLocation(openingBracePosition, this.clonePosition()); | ||
| if (argType === 'select') { | ||
| return { | ||
| val: { | ||
| type: TYPE.select, | ||
| value: value, | ||
| options: fromEntries(optionsResult.val), | ||
| location: location_2, | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| else { | ||
| return { | ||
| val: { | ||
| type: TYPE.plural, | ||
| value: value, | ||
| options: fromEntries(optionsResult.val), | ||
| offset: pluralOffset, | ||
| pluralType: argType === 'plural' ? 'cardinal' : 'ordinal', | ||
| location: location_2, | ||
| }, | ||
| err: null, | ||
| }; | ||
| } | ||
| } | ||
| default: | ||
| return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition)); | ||
| } | ||
| }; | ||
| Parser.prototype.tryParseArgumentClose = function (openingBracePosition) { | ||
| // Parse: {value, number, ::currency/GBP } | ||
| // | ||
| if (this.isEOF() || this.char() !== 125 /* `}` */) { | ||
| return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition())); | ||
| } | ||
| this.bump(); // `}` | ||
| return { val: true, err: null }; | ||
| }; | ||
| /** | ||
| * See: https://github.com/unicode-org/icu/blob/af7ed1f6d2298013dc303628438ec4abe1f16479/icu4c/source/common/messagepattern.cpp#L659 | ||
| */ | ||
| Parser.prototype.parseSimpleArgStyleIfPossible = function () { | ||
| var nestedBraces = 0; | ||
| var startPosition = this.clonePosition(); | ||
| while (!this.isEOF()) { | ||
| var ch = this.char(); | ||
| switch (ch) { | ||
| case 39 /* `'` */: { | ||
| // Treat apostrophe as quoting but include it in the style part. | ||
| // Find the end of the quoted literal text. | ||
| this.bump(); | ||
| var apostrophePosition = this.clonePosition(); | ||
| if (!this.bumpUntil("'")) { | ||
| return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition())); | ||
| } | ||
| this.bump(); | ||
| break; | ||
| } | ||
| case 123 /* `{` */: { | ||
| nestedBraces += 1; | ||
| this.bump(); | ||
| break; | ||
| } | ||
| case 125 /* `}` */: { | ||
| if (nestedBraces > 0) { | ||
| nestedBraces -= 1; | ||
| } | ||
| else { | ||
| return { | ||
| val: this.message.slice(startPosition.offset, this.offset()), | ||
| err: null, | ||
| }; | ||
| } | ||
| break; | ||
| } | ||
| default: | ||
| this.bump(); | ||
| break; | ||
| } | ||
| } | ||
| return { | ||
| val: this.message.slice(startPosition.offset, this.offset()), | ||
| err: null, | ||
| }; | ||
| }; | ||
| Parser.prototype.parseNumberSkeletonFromString = function (skeleton, location) { | ||
| var tokens = []; | ||
| try { | ||
| tokens = parseNumberSkeletonFromString(skeleton); | ||
| } | ||
| catch (e) { | ||
| return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location); | ||
| } | ||
| return { | ||
| val: { | ||
| type: SKELETON_TYPE.number, | ||
| tokens: tokens, | ||
| location: location, | ||
| parsedOptions: this.shouldParseSkeletons | ||
| ? parseNumberSkeleton(tokens) | ||
| : {}, | ||
| }, | ||
| err: null, | ||
| }; | ||
| }; | ||
| /** | ||
| * @param nesting_level The current nesting level of messages. | ||
| * This can be positive when parsing message fragment in select or plural argument options. | ||
| * @param parent_arg_type The parent argument's type. | ||
| * @param parsed_first_identifier If provided, this is the first identifier-like selector of | ||
| * the argument. It is a by-product of a previous parsing attempt. | ||
| * @param expecting_close_tag If true, this message is directly or indirectly nested inside | ||
| * between a pair of opening and closing tags. The nested message will not parse beyond | ||
| * the closing tag boundary. | ||
| */ | ||
| Parser.prototype.tryParsePluralOrSelectOptions = function (nestingLevel, parentArgType, expectCloseTag, parsedFirstIdentifier) { | ||
| var _a; | ||
| var hasOtherClause = false; | ||
| var options = []; | ||
| var parsedSelectors = new Set(); | ||
| var selector = parsedFirstIdentifier.value, selectorLocation = parsedFirstIdentifier.location; | ||
| // Parse: | ||
| // one {one apple} | ||
| // ^--^ | ||
| while (true) { | ||
| if (selector.length === 0) { | ||
| var startPosition = this.clonePosition(); | ||
| if (parentArgType !== 'select' && this.bumpIf('=')) { | ||
| // Try parse `={number}` selector | ||
| var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR); | ||
| if (result.err) { | ||
| return result; | ||
| } | ||
| selectorLocation = createLocation(startPosition, this.clonePosition()); | ||
| selector = this.message.slice(startPosition.offset, this.offset()); | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
| // Duplicate selector clauses | ||
| if (parsedSelectors.has(selector)) { | ||
| return this.error(parentArgType === 'select' | ||
| ? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR | ||
| : ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation); | ||
| } | ||
| if (selector === 'other') { | ||
| hasOtherClause = true; | ||
| } | ||
| // Parse: | ||
| // one {one apple} | ||
| // ^----------^ | ||
| this.bumpSpace(); | ||
| var openingBracePosition = this.clonePosition(); | ||
| if (!this.bumpIf('{')) { | ||
| return this.error(parentArgType === 'select' | ||
| ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT | ||
| : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition())); | ||
| } | ||
| var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag); | ||
| if (fragmentResult.err) { | ||
| return fragmentResult; | ||
| } | ||
| var argCloseResult = this.tryParseArgumentClose(openingBracePosition); | ||
| if (argCloseResult.err) { | ||
| return argCloseResult; | ||
| } | ||
| options.push([ | ||
| selector, | ||
| { | ||
| value: fragmentResult.val, | ||
| location: createLocation(openingBracePosition, this.clonePosition()), | ||
| }, | ||
| ]); | ||
| // Keep track of the existing selectors | ||
| parsedSelectors.add(selector); | ||
| // Prep next selector clause. | ||
| this.bumpSpace(); | ||
| (_a = this.parseIdentifierIfPossible(), selector = _a.value, selectorLocation = _a.location); | ||
| } | ||
| if (options.length === 0) { | ||
| return this.error(parentArgType === 'select' | ||
| ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR | ||
| : 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 { val: options, err: null }; | ||
| }; | ||
| Parser.prototype.tryParseDecimalInteger = function (expectNumberError, invalidNumberError) { | ||
| var sign = 1; | ||
| var startingPosition = this.clonePosition(); | ||
| if (this.bumpIf('+')) { | ||
| } | ||
| else if (this.bumpIf('-')) { | ||
| sign = -1; | ||
| } | ||
| var hasDigits = false; | ||
| var decimal = 0; | ||
| while (!this.isEOF()) { | ||
| var ch = this.char(); | ||
| if (ch >= 48 /* `0` */ && ch <= 57 /* `9` */) { | ||
| hasDigits = true; | ||
| decimal = decimal * 10 + (ch - 48); | ||
| this.bump(); | ||
| } | ||
| else { | ||
| break; | ||
| } | ||
| } | ||
| var location = createLocation(startingPosition, this.clonePosition()); | ||
| if (!hasDigits) { | ||
| return this.error(expectNumberError, location); | ||
| } | ||
| decimal *= sign; | ||
| if (!isSafeInteger(decimal)) { | ||
| return this.error(invalidNumberError, location); | ||
| } | ||
| return { val: decimal, err: null }; | ||
| }; | ||
| Parser.prototype.offset = function () { | ||
| return this.position.offset; | ||
| }; | ||
| Parser.prototype.isEOF = function () { | ||
| return this.offset() === this.message.length; | ||
| }; | ||
| Parser.prototype.clonePosition = function () { | ||
| // This is much faster than `Object.assign` or spread. | ||
| return { | ||
| offset: this.position.offset, | ||
| line: this.position.line, | ||
| column: this.position.column, | ||
| }; | ||
| }; | ||
| /** | ||
| * Return the code point at the current position of the parser. | ||
| * Throws if the index is out of bound. | ||
| */ | ||
| Parser.prototype.char = function () { | ||
| var offset = this.position.offset; | ||
| if (offset >= this.message.length) { | ||
| throw Error('out of bound'); | ||
| } | ||
| var code = codePointAt(this.message, offset); | ||
| if (code === undefined) { | ||
| throw Error("Offset ".concat(offset, " is at invalid UTF-16 code unit boundary")); | ||
| } | ||
| return code; | ||
| }; | ||
| Parser.prototype.error = function (kind, location) { | ||
| return { | ||
| val: null, | ||
| err: { | ||
| kind: kind, | ||
| message: this.message, | ||
| location: location, | ||
| }, | ||
| }; | ||
| }; | ||
| /** Bump the parser to the next UTF-16 code unit. */ | ||
| Parser.prototype.bump = function () { | ||
| if (this.isEOF()) { | ||
| return; | ||
| } | ||
| var code = this.char(); | ||
| if (code === 10 /* '\n' */) { | ||
| this.position.line += 1; | ||
| this.position.column = 1; | ||
| this.position.offset += 1; | ||
| } | ||
| else { | ||
| this.position.column += 1; | ||
| // 0 ~ 0x10000 -> unicode BMP, otherwise skip the surrogate pair. | ||
| this.position.offset += code < 0x10000 ? 1 : 2; | ||
| } | ||
| }; | ||
| /** | ||
| * If the substring starting at the current position of the parser has | ||
| * the given prefix, then bump the parser to the character immediately | ||
| * following the prefix and return true. Otherwise, don't bump the parser | ||
| * and return false. | ||
| */ | ||
| Parser.prototype.bumpIf = function (prefix) { | ||
| if (startsWith(this.message, prefix, this.offset())) { | ||
| for (var i = 0; i < prefix.length; i++) { | ||
| this.bump(); | ||
| } | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
| /** | ||
| * Bump the parser until the pattern character is found and return `true`. | ||
| * Otherwise bump to the end of the file and return `false`. | ||
| */ | ||
| Parser.prototype.bumpUntil = function (pattern) { | ||
| var currentOffset = this.offset(); | ||
| var index = this.message.indexOf(pattern, currentOffset); | ||
| if (index >= 0) { | ||
| this.bumpTo(index); | ||
| return true; | ||
| } | ||
| else { | ||
| this.bumpTo(this.message.length); | ||
| return false; | ||
| } | ||
| }; | ||
| /** | ||
| * Bump the parser to the target offset. | ||
| * If target offset is beyond the end of the input, bump the parser to the end of the input. | ||
| */ | ||
| Parser.prototype.bumpTo = function (targetOffset) { | ||
| if (this.offset() > targetOffset) { | ||
| throw Error("targetOffset ".concat(targetOffset, " must be greater than or equal to the current offset ").concat(this.offset())); | ||
| } | ||
| targetOffset = Math.min(targetOffset, this.message.length); | ||
| while (true) { | ||
| var offset = this.offset(); | ||
| if (offset === targetOffset) { | ||
| break; | ||
| } | ||
| if (offset > targetOffset) { | ||
| throw Error("targetOffset ".concat(targetOffset, " is at invalid UTF-16 code unit boundary")); | ||
| } | ||
| this.bump(); | ||
| if (this.isEOF()) { | ||
| break; | ||
| } | ||
| } | ||
| }; | ||
| /** advance the parser through all whitespace to the next non-whitespace code unit. */ | ||
| Parser.prototype.bumpSpace = function () { | ||
| while (!this.isEOF() && _isWhiteSpace(this.char())) { | ||
| this.bump(); | ||
| } | ||
| }; | ||
| /** | ||
| * Peek at the *next* Unicode codepoint in the input without advancing the parser. | ||
| * If the input has been exhausted, then this returns null. | ||
| */ | ||
| Parser.prototype.peek = function () { | ||
| if (this.isEOF()) { | ||
| return null; | ||
| } | ||
| var code = this.char(); | ||
| var offset = this.offset(); | ||
| var nextCode = this.message.charCodeAt(offset + (code >= 0x10000 ? 2 : 1)); | ||
| return nextCode !== null && nextCode !== void 0 ? nextCode : null; | ||
| }; | ||
| return Parser; | ||
| }()); | ||
| export { Parser }; | ||
| /** | ||
| * This check if codepoint is alphabet (lower & uppercase) | ||
| * @param codepoint | ||
| * @returns | ||
| */ | ||
| function _isAlpha(codepoint) { | ||
| return ((codepoint >= 97 && codepoint <= 122) || | ||
| (codepoint >= 65 && codepoint <= 90)); | ||
| } | ||
| function _isAlphaOrSlash(codepoint) { | ||
| return _isAlpha(codepoint) || codepoint === 47; /* '/' */ | ||
| } | ||
| /** See `parseTag` function docs. */ | ||
| function _isPotentialElementNameChar(c) { | ||
| return (c === 45 /* '-' */ || | ||
| c === 46 /* '.' */ || | ||
| (c >= 48 && c <= 57) /* 0..9 */ || | ||
| c === 95 /* '_' */ || | ||
| (c >= 97 && c <= 122) /** a..z */ || | ||
| (c >= 65 && c <= 90) /* A..Z */ || | ||
| c == 0xb7 || | ||
| (c >= 0xc0 && c <= 0xd6) || | ||
| (c >= 0xd8 && c <= 0xf6) || | ||
| (c >= 0xf8 && c <= 0x37d) || | ||
| (c >= 0x37f && c <= 0x1fff) || | ||
| (c >= 0x200c && c <= 0x200d) || | ||
| (c >= 0x203f && c <= 0x2040) || | ||
| (c >= 0x2070 && c <= 0x218f) || | ||
| (c >= 0x2c00 && c <= 0x2fef) || | ||
| (c >= 0x3001 && c <= 0xd7ff) || | ||
| (c >= 0xf900 && c <= 0xfdcf) || | ||
| (c >= 0xfdf0 && c <= 0xfffd) || | ||
| (c >= 0x10000 && c <= 0xeffff)); | ||
| } | ||
| /** | ||
| * Code point equivalent of regex `\p{White_Space}`. | ||
| * From: https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt | ||
| */ | ||
| function _isWhiteSpace(c) { | ||
| return ((c >= 0x0009 && c <= 0x000d) || | ||
| c === 0x0020 || | ||
| c === 0x0085 || | ||
| (c >= 0x200e && c <= 0x200f) || | ||
| c === 0x2028 || | ||
| c === 0x2029); | ||
| } | ||
| /** | ||
| * Code point equivalent of regex `\p{Pattern_Syntax}`. | ||
| * See https://www.unicode.org/Public/UCD/latest/ucd/PropList.txt | ||
| */ | ||
| function _isPatternSyntax(c) { | ||
| return ((c >= 0x0021 && c <= 0x0023) || | ||
| c === 0x0024 || | ||
| (c >= 0x0025 && c <= 0x0027) || | ||
| c === 0x0028 || | ||
| c === 0x0029 || | ||
| c === 0x002a || | ||
| c === 0x002b || | ||
| c === 0x002c || | ||
| c === 0x002d || | ||
| (c >= 0x002e && c <= 0x002f) || | ||
| (c >= 0x003a && c <= 0x003b) || | ||
| (c >= 0x003c && c <= 0x003e) || | ||
| (c >= 0x003f && c <= 0x0040) || | ||
| c === 0x005b || | ||
| c === 0x005c || | ||
| c === 0x005d || | ||
| c === 0x005e || | ||
| c === 0x0060 || | ||
| c === 0x007b || | ||
| c === 0x007c || | ||
| c === 0x007d || | ||
| c === 0x007e || | ||
| c === 0x00a1 || | ||
| (c >= 0x00a2 && c <= 0x00a5) || | ||
| c === 0x00a6 || | ||
| c === 0x00a7 || | ||
| c === 0x00a9 || | ||
| c === 0x00ab || | ||
| c === 0x00ac || | ||
| c === 0x00ae || | ||
| c === 0x00b0 || | ||
| c === 0x00b1 || | ||
| c === 0x00b6 || | ||
| c === 0x00bb || | ||
| c === 0x00bf || | ||
| c === 0x00d7 || | ||
| c === 0x00f7 || | ||
| (c >= 0x2010 && c <= 0x2015) || | ||
| (c >= 0x2016 && c <= 0x2017) || | ||
| c === 0x2018 || | ||
| c === 0x2019 || | ||
| c === 0x201a || | ||
| (c >= 0x201b && c <= 0x201c) || | ||
| c === 0x201d || | ||
| c === 0x201e || | ||
| c === 0x201f || | ||
| (c >= 0x2020 && c <= 0x2027) || | ||
| (c >= 0x2030 && c <= 0x2038) || | ||
| c === 0x2039 || | ||
| c === 0x203a || | ||
| (c >= 0x203b && c <= 0x203e) || | ||
| (c >= 0x2041 && c <= 0x2043) || | ||
| c === 0x2044 || | ||
| c === 0x2045 || | ||
| c === 0x2046 || | ||
| (c >= 0x2047 && c <= 0x2051) || | ||
| c === 0x2052 || | ||
| c === 0x2053 || | ||
| (c >= 0x2055 && c <= 0x205e) || | ||
| (c >= 0x2190 && c <= 0x2194) || | ||
| (c >= 0x2195 && c <= 0x2199) || | ||
| (c >= 0x219a && c <= 0x219b) || | ||
| (c >= 0x219c && c <= 0x219f) || | ||
| c === 0x21a0 || | ||
| (c >= 0x21a1 && c <= 0x21a2) || | ||
| c === 0x21a3 || | ||
| (c >= 0x21a4 && c <= 0x21a5) || | ||
| c === 0x21a6 || | ||
| (c >= 0x21a7 && c <= 0x21ad) || | ||
| c === 0x21ae || | ||
| (c >= 0x21af && c <= 0x21cd) || | ||
| (c >= 0x21ce && c <= 0x21cf) || | ||
| (c >= 0x21d0 && c <= 0x21d1) || | ||
| c === 0x21d2 || | ||
| c === 0x21d3 || | ||
| c === 0x21d4 || | ||
| (c >= 0x21d5 && c <= 0x21f3) || | ||
| (c >= 0x21f4 && c <= 0x22ff) || | ||
| (c >= 0x2300 && c <= 0x2307) || | ||
| c === 0x2308 || | ||
| c === 0x2309 || | ||
| c === 0x230a || | ||
| c === 0x230b || | ||
| (c >= 0x230c && c <= 0x231f) || | ||
| (c >= 0x2320 && c <= 0x2321) || | ||
| (c >= 0x2322 && c <= 0x2328) || | ||
| c === 0x2329 || | ||
| c === 0x232a || | ||
| (c >= 0x232b && c <= 0x237b) || | ||
| c === 0x237c || | ||
| (c >= 0x237d && c <= 0x239a) || | ||
| (c >= 0x239b && c <= 0x23b3) || | ||
| (c >= 0x23b4 && c <= 0x23db) || | ||
| (c >= 0x23dc && c <= 0x23e1) || | ||
| (c >= 0x23e2 && c <= 0x2426) || | ||
| (c >= 0x2427 && c <= 0x243f) || | ||
| (c >= 0x2440 && c <= 0x244a) || | ||
| (c >= 0x244b && c <= 0x245f) || | ||
| (c >= 0x2500 && c <= 0x25b6) || | ||
| c === 0x25b7 || | ||
| (c >= 0x25b8 && c <= 0x25c0) || | ||
| c === 0x25c1 || | ||
| (c >= 0x25c2 && c <= 0x25f7) || | ||
| (c >= 0x25f8 && c <= 0x25ff) || | ||
| (c >= 0x2600 && c <= 0x266e) || | ||
| c === 0x266f || | ||
| (c >= 0x2670 && c <= 0x2767) || | ||
| c === 0x2768 || | ||
| c === 0x2769 || | ||
| c === 0x276a || | ||
| c === 0x276b || | ||
| c === 0x276c || | ||
| c === 0x276d || | ||
| c === 0x276e || | ||
| c === 0x276f || | ||
| c === 0x2770 || | ||
| c === 0x2771 || | ||
| c === 0x2772 || | ||
| c === 0x2773 || | ||
| c === 0x2774 || | ||
| c === 0x2775 || | ||
| (c >= 0x2794 && c <= 0x27bf) || | ||
| (c >= 0x27c0 && c <= 0x27c4) || | ||
| c === 0x27c5 || | ||
| c === 0x27c6 || | ||
| (c >= 0x27c7 && c <= 0x27e5) || | ||
| c === 0x27e6 || | ||
| c === 0x27e7 || | ||
| c === 0x27e8 || | ||
| c === 0x27e9 || | ||
| c === 0x27ea || | ||
| c === 0x27eb || | ||
| c === 0x27ec || | ||
| c === 0x27ed || | ||
| c === 0x27ee || | ||
| c === 0x27ef || | ||
| (c >= 0x27f0 && c <= 0x27ff) || | ||
| (c >= 0x2800 && c <= 0x28ff) || | ||
| (c >= 0x2900 && c <= 0x2982) || | ||
| c === 0x2983 || | ||
| c === 0x2984 || | ||
| c === 0x2985 || | ||
| c === 0x2986 || | ||
| c === 0x2987 || | ||
| c === 0x2988 || | ||
| c === 0x2989 || | ||
| c === 0x298a || | ||
| c === 0x298b || | ||
| c === 0x298c || | ||
| c === 0x298d || | ||
| c === 0x298e || | ||
| c === 0x298f || | ||
| c === 0x2990 || | ||
| c === 0x2991 || | ||
| c === 0x2992 || | ||
| c === 0x2993 || | ||
| c === 0x2994 || | ||
| c === 0x2995 || | ||
| c === 0x2996 || | ||
| c === 0x2997 || | ||
| c === 0x2998 || | ||
| (c >= 0x2999 && c <= 0x29d7) || | ||
| c === 0x29d8 || | ||
| c === 0x29d9 || | ||
| c === 0x29da || | ||
| c === 0x29db || | ||
| (c >= 0x29dc && c <= 0x29fb) || | ||
| c === 0x29fc || | ||
| c === 0x29fd || | ||
| (c >= 0x29fe && c <= 0x2aff) || | ||
| (c >= 0x2b00 && c <= 0x2b2f) || | ||
| (c >= 0x2b30 && c <= 0x2b44) || | ||
| (c >= 0x2b45 && c <= 0x2b46) || | ||
| (c >= 0x2b47 && c <= 0x2b4c) || | ||
| (c >= 0x2b4d && c <= 0x2b73) || | ||
| (c >= 0x2b74 && c <= 0x2b75) || | ||
| (c >= 0x2b76 && c <= 0x2b95) || | ||
| c === 0x2b96 || | ||
| (c >= 0x2b97 && c <= 0x2bff) || | ||
| (c >= 0x2e00 && c <= 0x2e01) || | ||
| c === 0x2e02 || | ||
| c === 0x2e03 || | ||
| c === 0x2e04 || | ||
| c === 0x2e05 || | ||
| (c >= 0x2e06 && c <= 0x2e08) || | ||
| c === 0x2e09 || | ||
| c === 0x2e0a || | ||
| c === 0x2e0b || | ||
| c === 0x2e0c || | ||
| c === 0x2e0d || | ||
| (c >= 0x2e0e && c <= 0x2e16) || | ||
| c === 0x2e17 || | ||
| (c >= 0x2e18 && c <= 0x2e19) || | ||
| c === 0x2e1a || | ||
| c === 0x2e1b || | ||
| c === 0x2e1c || | ||
| c === 0x2e1d || | ||
| (c >= 0x2e1e && c <= 0x2e1f) || | ||
| c === 0x2e20 || | ||
| c === 0x2e21 || | ||
| c === 0x2e22 || | ||
| c === 0x2e23 || | ||
| c === 0x2e24 || | ||
| c === 0x2e25 || | ||
| c === 0x2e26 || | ||
| c === 0x2e27 || | ||
| c === 0x2e28 || | ||
| c === 0x2e29 || | ||
| (c >= 0x2e2a && c <= 0x2e2e) || | ||
| c === 0x2e2f || | ||
| (c >= 0x2e30 && c <= 0x2e39) || | ||
| (c >= 0x2e3a && c <= 0x2e3b) || | ||
| (c >= 0x2e3c && c <= 0x2e3f) || | ||
| c === 0x2e40 || | ||
| c === 0x2e41 || | ||
| c === 0x2e42 || | ||
| (c >= 0x2e43 && c <= 0x2e4f) || | ||
| (c >= 0x2e50 && c <= 0x2e51) || | ||
| c === 0x2e52 || | ||
| (c >= 0x2e53 && c <= 0x2e7f) || | ||
| (c >= 0x3001 && c <= 0x3003) || | ||
| c === 0x3008 || | ||
| c === 0x3009 || | ||
| c === 0x300a || | ||
| c === 0x300b || | ||
| c === 0x300c || | ||
| c === 0x300d || | ||
| c === 0x300e || | ||
| c === 0x300f || | ||
| c === 0x3010 || | ||
| c === 0x3011 || | ||
| (c >= 0x3012 && c <= 0x3013) || | ||
| c === 0x3014 || | ||
| c === 0x3015 || | ||
| c === 0x3016 || | ||
| c === 0x3017 || | ||
| c === 0x3018 || | ||
| c === 0x3019 || | ||
| c === 0x301a || | ||
| c === 0x301b || | ||
| c === 0x301c || | ||
| c === 0x301d || | ||
| (c >= 0x301e && c <= 0x301f) || | ||
| c === 0x3020 || | ||
| c === 0x3030 || | ||
| c === 0xfd3e || | ||
| c === 0xfd3f || | ||
| (c >= 0xfe45 && c <= 0xfe46)); | ||
| } |
| import { DateTimeSkeleton, MessageFormatElement } from './types'; | ||
| export declare function printAST(ast: MessageFormatElement[]): string; | ||
| export declare function doPrintAST(ast: MessageFormatElement[], isInPlural: boolean): string; | ||
| export declare function printDateTimeSkeleton(style: DateTimeSkeleton): string; |
-101
| import { __spreadArray } from "tslib"; | ||
| import { isArgumentElement, isDateElement, isLiteralElement, isNumberElement, isPluralElement, isPoundElement, isSelectElement, isTagElement, isTimeElement, SKELETON_TYPE, TYPE, } from './types'; | ||
| export function printAST(ast) { | ||
| return doPrintAST(ast, false); | ||
| } | ||
| export function doPrintAST(ast, isInPlural) { | ||
| var printedNodes = ast.map(function (el, i) { | ||
| if (isLiteralElement(el)) { | ||
| return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1); | ||
| } | ||
| if (isArgumentElement(el)) { | ||
| return printArgumentElement(el); | ||
| } | ||
| if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) { | ||
| return printSimpleFormatElement(el); | ||
| } | ||
| if (isPluralElement(el)) { | ||
| return printPluralElement(el); | ||
| } | ||
| if (isSelectElement(el)) { | ||
| return printSelectElement(el); | ||
| } | ||
| if (isPoundElement(el)) { | ||
| return '#'; | ||
| } | ||
| if (isTagElement(el)) { | ||
| return printTagElement(el); | ||
| } | ||
| }); | ||
| return printedNodes.join(''); | ||
| } | ||
| function printTagElement(el) { | ||
| return "<".concat(el.value, ">").concat(printAST(el.children), "</").concat(el.value, ">"); | ||
| } | ||
| function printEscapedMessage(message) { | ||
| return message.replace(/([{}](?:[\s\S]*[{}])?)/, "'$1'"); | ||
| } | ||
| function printLiteralElement(_a, isInPlural, isFirstEl, isLastEl) { | ||
| var value = _a.value; | ||
| var escaped = value; | ||
| // If this literal starts with a ' and its not the 1st node, this means the node before it is non-literal | ||
| // and the `'` needs to be unescaped | ||
| if (!isFirstEl && escaped[0] === "'") { | ||
| escaped = "''".concat(escaped.slice(1)); | ||
| } | ||
| // Same logic but for last el | ||
| if (!isLastEl && escaped[escaped.length - 1] === "'") { | ||
| escaped = "".concat(escaped.slice(0, escaped.length - 1), "''"); | ||
| } | ||
| escaped = printEscapedMessage(escaped); | ||
| return isInPlural ? escaped.replace('#', "'#'") : escaped; | ||
| } | ||
| function printArgumentElement(_a) { | ||
| var value = _a.value; | ||
| return "{".concat(value, "}"); | ||
| } | ||
| function printSimpleFormatElement(el) { | ||
| return "{".concat(el.value, ", ").concat(TYPE[el.type]).concat(el.style ? ", ".concat(printArgumentStyle(el.style)) : '', "}"); | ||
| } | ||
| function printNumberSkeletonToken(token) { | ||
| var stem = token.stem, options = token.options; | ||
| return options.length === 0 | ||
| ? stem | ||
| : "".concat(stem).concat(options.map(function (o) { return "/".concat(o); }).join('')); | ||
| } | ||
| function printArgumentStyle(style) { | ||
| if (typeof style === 'string') { | ||
| return printEscapedMessage(style); | ||
| } | ||
| else if (style.type === SKELETON_TYPE.dateTime) { | ||
| return "::".concat(printDateTimeSkeleton(style)); | ||
| } | ||
| else { | ||
| return "::".concat(style.tokens.map(printNumberSkeletonToken).join(' ')); | ||
| } | ||
| } | ||
| export function printDateTimeSkeleton(style) { | ||
| return style.pattern; | ||
| } | ||
| function printSelectElement(el) { | ||
| var msg = [ | ||
| el.value, | ||
| 'select', | ||
| Object.keys(el.options) | ||
| .map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, false), "}"); }) | ||
| .join(' '), | ||
| ].join(','); | ||
| return "{".concat(msg, "}"); | ||
| } | ||
| function printPluralElement(el) { | ||
| var type = el.pluralType === 'cardinal' ? 'plural' : 'selectordinal'; | ||
| var msg = [ | ||
| el.value, | ||
| type, | ||
| __spreadArray([ | ||
| el.offset ? "offset:".concat(el.offset) : '' | ||
| ], Object.keys(el.options).map(function (id) { return "".concat(id, "{").concat(doPrintAST(el.options[id].value, true), "}"); }), true).filter(Boolean) | ||
| .join(' '), | ||
| ].join(','); | ||
| return "{".concat(msg, "}"); | ||
| } |
| export declare const SPACE_SEPARATOR_REGEX: RegExp; | ||
| export declare const WHITE_SPACE_REGEX: RegExp; |
| // @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]/; |
| export declare const timeData: Record<string, string[]>; |
| // @generated from time-data-gen.ts | ||
| // prettier-ignore | ||
| export var timeData = { | ||
| "001": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "419": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "AC": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "AD": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AE": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "AF": [ | ||
| "H", | ||
| "hb", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "AG": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AI": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "AL": [ | ||
| "h", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AM": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AO": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AR": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "AS": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "AT": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AU": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AW": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "AX": [ | ||
| "H" | ||
| ], | ||
| "AZ": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "BA": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "BB": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BD": [ | ||
| "h", | ||
| "hB", | ||
| "H" | ||
| ], | ||
| "BE": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BF": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BG": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "BH": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "BI": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "BJ": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BL": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BN": [ | ||
| "hb", | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "BO": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "BQ": [ | ||
| "H" | ||
| ], | ||
| "BR": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BS": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "BT": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "BW": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "BY": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "BZ": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "CA": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "CC": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "CD": [ | ||
| "hB", | ||
| "H" | ||
| ], | ||
| "CF": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "CG": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "CH": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "CI": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "CK": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "CL": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "CM": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "CN": [ | ||
| "H", | ||
| "hB", | ||
| "hb", | ||
| "h" | ||
| ], | ||
| "CO": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "CP": [ | ||
| "H" | ||
| ], | ||
| "CR": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "CU": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "CV": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "CW": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "CX": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "CY": [ | ||
| "h", | ||
| "H", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "CZ": [ | ||
| "H" | ||
| ], | ||
| "DE": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "DG": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "DJ": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "DK": [ | ||
| "H" | ||
| ], | ||
| "DM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "DO": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "DZ": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "EA": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "EC": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "EE": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "EG": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "EH": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "ER": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "ES": [ | ||
| "H", | ||
| "hB", | ||
| "h", | ||
| "hb" | ||
| ], | ||
| "ET": [ | ||
| "hB", | ||
| "hb", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "FI": [ | ||
| "H" | ||
| ], | ||
| "FJ": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "FK": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "FM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "FO": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "FR": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GA": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GB": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "GD": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GE": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "GF": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GG": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "GH": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "GI": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "GL": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "GM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GN": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GP": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GQ": [ | ||
| "H", | ||
| "hB", | ||
| "h", | ||
| "hb" | ||
| ], | ||
| "GR": [ | ||
| "h", | ||
| "H", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "GT": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "GU": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GW": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "GY": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "HK": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "HN": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "HR": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "HU": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "IC": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "ID": [ | ||
| "H" | ||
| ], | ||
| "IE": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "IL": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "IM": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "IN": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "IO": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "IQ": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "IR": [ | ||
| "hB", | ||
| "H" | ||
| ], | ||
| "IS": [ | ||
| "H" | ||
| ], | ||
| "IT": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "JE": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "JM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "JO": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "JP": [ | ||
| "H", | ||
| "K", | ||
| "h" | ||
| ], | ||
| "KE": [ | ||
| "hB", | ||
| "hb", | ||
| "H", | ||
| "h" | ||
| ], | ||
| "KG": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "KH": [ | ||
| "hB", | ||
| "h", | ||
| "H", | ||
| "hb" | ||
| ], | ||
| "KI": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "KM": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "KN": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "KP": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "KR": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "KW": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "KY": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "KZ": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "LA": [ | ||
| "H", | ||
| "hb", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "LB": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "LC": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "LI": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "LK": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "LR": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "LS": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "LT": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "LU": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "LV": [ | ||
| "H", | ||
| "hB", | ||
| "hb", | ||
| "h" | ||
| ], | ||
| "LY": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "MA": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "MC": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MD": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "ME": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "MF": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MG": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "MH": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MK": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "ML": [ | ||
| "H" | ||
| ], | ||
| "MM": [ | ||
| "hB", | ||
| "hb", | ||
| "H", | ||
| "h" | ||
| ], | ||
| "MN": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "MO": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "MP": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MQ": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MR": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "MS": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "MT": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "MU": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "MV": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "MW": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "MX": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "MY": [ | ||
| "hb", | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "MZ": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "NA": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "NC": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "NE": [ | ||
| "H" | ||
| ], | ||
| "NF": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "NG": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "NI": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "NL": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "NO": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "NP": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "NR": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "NU": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "NZ": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "OM": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "PA": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "PE": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "PF": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "PG": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "PH": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "PK": [ | ||
| "h", | ||
| "hB", | ||
| "H" | ||
| ], | ||
| "PL": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "PM": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "PN": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "PR": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "PS": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "PT": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "PW": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "PY": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "QA": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "RE": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "RO": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "RS": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "RU": [ | ||
| "H" | ||
| ], | ||
| "RW": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "SA": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "SB": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SC": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "SD": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "SE": [ | ||
| "H" | ||
| ], | ||
| "SG": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SH": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "SI": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SJ": [ | ||
| "H" | ||
| ], | ||
| "SK": [ | ||
| "H" | ||
| ], | ||
| "SL": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SM": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "SN": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "SO": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "SR": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SS": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "ST": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "SV": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "SX": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "SY": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "SZ": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TA": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "TC": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TD": [ | ||
| "h", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TF": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "TG": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TH": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "TJ": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "TL": [ | ||
| "H", | ||
| "hB", | ||
| "hb", | ||
| "h" | ||
| ], | ||
| "TM": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "TN": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "TO": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "TR": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TT": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "TW": [ | ||
| "hB", | ||
| "hb", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "TZ": [ | ||
| "hB", | ||
| "hb", | ||
| "H", | ||
| "h" | ||
| ], | ||
| "UA": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "UG": [ | ||
| "hB", | ||
| "hb", | ||
| "H", | ||
| "h" | ||
| ], | ||
| "UM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "US": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "UY": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "UZ": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "VA": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "VC": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "VE": [ | ||
| "h", | ||
| "H", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "VG": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "VI": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "VN": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "VU": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "WF": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "WS": [ | ||
| "h", | ||
| "H" | ||
| ], | ||
| "XK": [ | ||
| "H", | ||
| "hB", | ||
| "h" | ||
| ], | ||
| "YE": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "YT": [ | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "ZA": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "ZM": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "ZW": [ | ||
| "H", | ||
| "h" | ||
| ], | ||
| "af-ZA": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "ar-001": [ | ||
| "h", | ||
| "hB", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "ca-ES": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "en-001": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "en-HK": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "en-IL": [ | ||
| "H", | ||
| "h", | ||
| "hb", | ||
| "hB" | ||
| ], | ||
| "en-MY": [ | ||
| "h", | ||
| "hb", | ||
| "H", | ||
| "hB" | ||
| ], | ||
| "es-BR": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "es-ES": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "es-GQ": [ | ||
| "H", | ||
| "h", | ||
| "hB", | ||
| "hb" | ||
| ], | ||
| "fr-CA": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "gl-ES": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "gu-IN": [ | ||
| "hB", | ||
| "hb", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "hi-IN": [ | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "it-CH": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "it-IT": [ | ||
| "H", | ||
| "h", | ||
| "hB" | ||
| ], | ||
| "kn-IN": [ | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "ml-IN": [ | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "mr-IN": [ | ||
| "hB", | ||
| "hb", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "pa-IN": [ | ||
| "hB", | ||
| "hb", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "ta-IN": [ | ||
| "hB", | ||
| "h", | ||
| "hb", | ||
| "H" | ||
| ], | ||
| "te-IN": [ | ||
| "hB", | ||
| "h", | ||
| "H" | ||
| ], | ||
| "zu-ZA": [ | ||
| "H", | ||
| "hB", | ||
| "hb", | ||
| "h" | ||
| ] | ||
| }; |
-120
| import type { NumberFormatOptions } from '@formatjs/ecma402-abstract'; | ||
| import { NumberSkeletonToken } from '@formatjs/icu-skeleton-parser'; | ||
| export interface ExtendedNumberFormatOptions extends NumberFormatOptions { | ||
| scale?: number; | ||
| } | ||
| export declare enum TYPE { | ||
| /** | ||
| * Raw text | ||
| */ | ||
| literal = 0, | ||
| /** | ||
| * Variable w/o any format, e.g `var` in `this is a {var}` | ||
| */ | ||
| argument = 1, | ||
| /** | ||
| * Variable w/ number format | ||
| */ | ||
| number = 2, | ||
| /** | ||
| * Variable w/ date format | ||
| */ | ||
| date = 3, | ||
| /** | ||
| * Variable w/ time format | ||
| */ | ||
| time = 4, | ||
| /** | ||
| * Variable w/ select format | ||
| */ | ||
| select = 5, | ||
| /** | ||
| * Variable w/ plural format | ||
| */ | ||
| plural = 6, | ||
| /** | ||
| * Only possible within plural argument. | ||
| * This is the `#` symbol that will be substituted with the count. | ||
| */ | ||
| pound = 7, | ||
| /** | ||
| * XML-like tag | ||
| */ | ||
| tag = 8 | ||
| } | ||
| export declare enum SKELETON_TYPE { | ||
| number = 0, | ||
| dateTime = 1 | ||
| } | ||
| export interface LocationDetails { | ||
| offset: number; | ||
| line: number; | ||
| column: number; | ||
| } | ||
| export interface Location { | ||
| start: LocationDetails; | ||
| end: LocationDetails; | ||
| } | ||
| export interface BaseElement<T extends TYPE> { | ||
| type: T; | ||
| value: string; | ||
| location?: Location; | ||
| } | ||
| export type LiteralElement = BaseElement<TYPE.literal>; | ||
| export type ArgumentElement = BaseElement<TYPE.argument>; | ||
| export interface TagElement extends BaseElement<TYPE.tag> { | ||
| children: MessageFormatElement[]; | ||
| } | ||
| export interface SimpleFormatElement<T extends TYPE, S extends Skeleton> extends BaseElement<T> { | ||
| style?: string | S | null; | ||
| } | ||
| export type NumberElement = SimpleFormatElement<TYPE.number, NumberSkeleton>; | ||
| export type DateElement = SimpleFormatElement<TYPE.date, DateTimeSkeleton>; | ||
| export type TimeElement = SimpleFormatElement<TYPE.time, DateTimeSkeleton>; | ||
| export type ValidPluralRule = 'zero' | 'one' | 'two' | 'few' | 'many' | 'other' | string; | ||
| export interface PluralOrSelectOption { | ||
| value: MessageFormatElement[]; | ||
| location?: Location; | ||
| } | ||
| export interface SelectElement extends BaseElement<TYPE.select> { | ||
| options: Record<string, PluralOrSelectOption>; | ||
| } | ||
| export interface PluralElement extends BaseElement<TYPE.plural> { | ||
| options: Record<ValidPluralRule, PluralOrSelectOption>; | ||
| offset: number; | ||
| pluralType: Intl.PluralRulesOptions['type']; | ||
| } | ||
| export interface PoundElement { | ||
| type: TYPE.pound; | ||
| location?: Location; | ||
| } | ||
| export type MessageFormatElement = ArgumentElement | DateElement | LiteralElement | NumberElement | PluralElement | PoundElement | SelectElement | TagElement | TimeElement; | ||
| export interface NumberSkeleton { | ||
| type: SKELETON_TYPE.number; | ||
| tokens: NumberSkeletonToken[]; | ||
| location?: Location; | ||
| parsedOptions: ExtendedNumberFormatOptions; | ||
| } | ||
| export interface DateTimeSkeleton { | ||
| type: SKELETON_TYPE.dateTime; | ||
| pattern: string; | ||
| location?: Location; | ||
| parsedOptions: Intl.DateTimeFormatOptions; | ||
| } | ||
| export type Skeleton = NumberSkeleton | DateTimeSkeleton; | ||
| /** | ||
| * Type Guards | ||
| */ | ||
| export declare function isLiteralElement(el: MessageFormatElement): el is LiteralElement; | ||
| export declare function isArgumentElement(el: MessageFormatElement): el is ArgumentElement; | ||
| export declare function isNumberElement(el: MessageFormatElement): el is NumberElement; | ||
| export declare function isDateElement(el: MessageFormatElement): el is DateElement; | ||
| export declare function isTimeElement(el: MessageFormatElement): el is TimeElement; | ||
| export declare function isSelectElement(el: MessageFormatElement): el is SelectElement; | ||
| export declare function isPluralElement(el: MessageFormatElement): el is PluralElement; | ||
| export declare function isPoundElement(el: MessageFormatElement): el is PoundElement; | ||
| export declare function isTagElement(el: MessageFormatElement): el is TagElement; | ||
| export declare function isNumberSkeleton(el: NumberElement['style'] | Skeleton): el is NumberSkeleton; | ||
| export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style'] | Skeleton): el is DateTimeSkeleton; | ||
| export declare function createLiteralElement(value: string): LiteralElement; | ||
| export declare function createNumberElement(value: string, style?: string | null): NumberElement; |
-94
| export var TYPE; | ||
| (function (TYPE) { | ||
| /** | ||
| * Raw text | ||
| */ | ||
| TYPE[TYPE["literal"] = 0] = "literal"; | ||
| /** | ||
| * Variable w/o any format, e.g `var` in `this is a {var}` | ||
| */ | ||
| TYPE[TYPE["argument"] = 1] = "argument"; | ||
| /** | ||
| * Variable w/ number format | ||
| */ | ||
| TYPE[TYPE["number"] = 2] = "number"; | ||
| /** | ||
| * Variable w/ date format | ||
| */ | ||
| TYPE[TYPE["date"] = 3] = "date"; | ||
| /** | ||
| * Variable w/ time format | ||
| */ | ||
| TYPE[TYPE["time"] = 4] = "time"; | ||
| /** | ||
| * Variable w/ select format | ||
| */ | ||
| TYPE[TYPE["select"] = 5] = "select"; | ||
| /** | ||
| * Variable w/ plural format | ||
| */ | ||
| TYPE[TYPE["plural"] = 6] = "plural"; | ||
| /** | ||
| * Only possible within plural argument. | ||
| * This is the `#` symbol that will be substituted with the count. | ||
| */ | ||
| TYPE[TYPE["pound"] = 7] = "pound"; | ||
| /** | ||
| * XML-like tag | ||
| */ | ||
| TYPE[TYPE["tag"] = 8] = "tag"; | ||
| })(TYPE || (TYPE = {})); | ||
| export var SKELETON_TYPE; | ||
| (function (SKELETON_TYPE) { | ||
| SKELETON_TYPE[SKELETON_TYPE["number"] = 0] = "number"; | ||
| SKELETON_TYPE[SKELETON_TYPE["dateTime"] = 1] = "dateTime"; | ||
| })(SKELETON_TYPE || (SKELETON_TYPE = {})); | ||
| /** | ||
| * Type Guards | ||
| */ | ||
| export function isLiteralElement(el) { | ||
| return el.type === TYPE.literal; | ||
| } | ||
| export function isArgumentElement(el) { | ||
| return el.type === TYPE.argument; | ||
| } | ||
| export function isNumberElement(el) { | ||
| return el.type === TYPE.number; | ||
| } | ||
| export function isDateElement(el) { | ||
| return el.type === TYPE.date; | ||
| } | ||
| export function isTimeElement(el) { | ||
| return el.type === TYPE.time; | ||
| } | ||
| export function isSelectElement(el) { | ||
| return el.type === TYPE.select; | ||
| } | ||
| export function isPluralElement(el) { | ||
| return el.type === TYPE.plural; | ||
| } | ||
| export function isPoundElement(el) { | ||
| return el.type === TYPE.pound; | ||
| } | ||
| export function isTagElement(el) { | ||
| return el.type === TYPE.tag; | ||
| } | ||
| export function isNumberSkeleton(el) { | ||
| return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.number); | ||
| } | ||
| export function isDateTimeSkeleton(el) { | ||
| return !!(el && typeof el === 'object' && el.type === SKELETON_TYPE.dateTime); | ||
| } | ||
| export function createLiteralElement(value) { | ||
| return { | ||
| type: TYPE.literal, | ||
| value: value, | ||
| }; | ||
| } | ||
| export function createNumberElement(value, style) { | ||
| return { | ||
| type: TYPE.number, | ||
| value: value, | ||
| style: style, | ||
| }; | ||
| } |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
6
-45.45%Yes
NaN103939
-50.02%23
-46.51%3611
-50.35%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed