Skip to content

Commit

Permalink
fix(storefront): STRF-12688 Update messageformat dependency version
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwiese committed Dec 16, 2024
1 parent 79540c9 commit 40029e6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/translator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Translator.prototype._compileTemplate = function (key) {
try {
return formatter.compile(this._language.translations[key]);
} catch (err) {
if (err.name === 'SyntaxError') {
if (err.name === 'Error') {
this._logger.warn(`Language File Syntax Error: ${err.message} for key "${key}"`, err.expected);
return () => '';
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"lint": "eslint .",
"lint-and-fix": "eslint . --fix",
"test": "lab -v -t 95 --ignore i18n,WebAssembly,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask,FinalizationRegistry,WeakRef,plural,en,number,select,__extends,__assign,__rest,__decorate,__param,__esDecorate,__runInitializers,__propKey,__setFunctionName,__metadata,__awaiter,__generator,__exportStar,__createBinding,__values,__read,__spread,__spreadArrays,__spreadArray,__await,__asyncGenerator,__asyncDelegator,__asyncValues,__makeTemplateObject,__importStar,__importDefault,__classPrivateFieldGet,__classPrivateFieldSet,__classPrivateFieldIn,AggregateError,BroadcastChannel,structuredClone,DOMException,AbortController,AbortSignal,EventTarget,Event,MessageChannel,MessagePort,MessageEvent,atob,btoa,Blob,Performance,performance,ReadableStream,ReadableStreamDefaultReader,ReadableStreamBYOBReader,ReadableStreamBYOBRequest,ReadableByteStreamController,ReadableStreamDefaultController,TransformStream,TransformStreamDefaultController,WritableStream,WritableStreamDefaultWriter,WritableStreamDefaultController,ByteLengthQueuingStrategy,CountQueuingStrategy,TextEncoderStream,TextDecoderStream,CompressionStream,DecompressionStream,fetch,FormData,Headers,Request,Response,__addDisposableResource,__disposeResources,File,PerformanceEntry,PerformanceMark,PerformanceMeasure,PerformanceObserver,PerformanceObserverEntryList,PerformanceResourceTiming,WebSocket,Iterator,Navigator,navigator,crypto,Crypto,CryptoKey,SubtleCrypto,CustomEvent spec",
"test": "lab -v -t 94 --ignore i18n,WebAssembly,SharedArrayBuffer,Atomics,BigUint64Array,BigInt64Array,BigInt,URL,URLSearchParams,TextEncoder,TextDecoder,queueMicrotask,FinalizationRegistry,WeakRef,plural,en,number,select,__extends,__assign,__rest,__decorate,__param,__esDecorate,__runInitializers,__propKey,__setFunctionName,__metadata,__awaiter,__generator,__exportStar,__createBinding,__values,__read,__spread,__spreadArrays,__spreadArray,__await,__asyncGenerator,__asyncDelegator,__asyncValues,__makeTemplateObject,__importStar,__importDefault,__classPrivateFieldGet,__classPrivateFieldSet,__classPrivateFieldIn,__rewriteRelativeImportExtension,AggregateError,BroadcastChannel,structuredClone,DOMException,AbortController,AbortSignal,EventTarget,Event,MessageChannel,MessagePort,MessageEvent,atob,btoa,Blob,Performance,performance,ReadableStream,ReadableStreamDefaultReader,ReadableStreamBYOBReader,ReadableStreamBYOBRequest,ReadableByteStreamController,ReadableStreamDefaultController,TransformStream,TransformStreamDefaultController,WritableStream,WritableStreamDefaultWriter,WritableStreamDefaultController,ByteLengthQueuingStrategy,CountQueuingStrategy,TextEncoderStream,TextDecoderStream,CompressionStream,DecompressionStream,fetch,FormData,Headers,Request,Response,__addDisposableResource,__disposeResources,File,PerformanceEntry,PerformanceMark,PerformanceMeasure,PerformanceObserver,PerformanceObserverEntryList,PerformanceResourceTiming,WebSocket,Iterator,Navigator,navigator,crypto,Crypto,CryptoKey,SubtleCrypto,CustomEvent spec",
"coverage": "lab -c -r console -o stdout -r html -o coverage.html spec",
"release": "semantic-release"
},
Expand All @@ -27,7 +27,7 @@
"dependencies": {
"@bigcommerce/stencil-paper-handlebars": "6.0.2",
"accept-language-parser": "~1.4.1",
"messageformat": "~0.2.2"
"messageformat": "~0.3.1"
},
"devDependencies": {
"@commitlint/cli": "^19.4.0",
Expand Down
13 changes: 9 additions & 4 deletions spec/lib/translator.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ describe('Translator', () => {

expect(translator.translate('hello')).to.equal('');
expect(loggerStub.warn.called).to.equal(true);
expect(loggerStub.warn.getCall(0).args[0]).to.equal("MessageFormat: Data required for 'name'.")
expect(loggerStub.warn.getCall(0).args[0]).to.equal("Cannot read properties of undefined (reading 'name')")

done();
});
Expand All @@ -145,7 +145,7 @@ describe('Translator', () => {
}, loggerStub);

const result = translator.translate('items_with_syntax_error', { count: 1 });
const errMessage = 'Language File Syntax Error: Expected "plural" or "select" but "p" found. for key "items_with_syntax_error"';
const errMessage = 'Language File Syntax Error: Parser error: SyntaxError: Expected "," or "}" but "{" found. for key "items_with_syntax_error"';
expect(result).to.equal("");
expect(loggerStub.warn.called).to.equal(true);
expect(loggerStub.warn.getCall(0).args[0]).to.equal(errMessage);
Expand All @@ -158,9 +158,14 @@ describe('Translator', () => {
en: {
gender_error: '{gender, select, male{He} female{She}} liked this.',
},
});
}, loggerStub);

const result = translator.translate('gender_error', { gender: 'asdf' });

expect(() => translator.translate('gender_error', { gender: 'asdf' })).to.throw(Error);
const errMessage = 'Language File Syntax Error: Precompiler error: Error: No \'other\' form found in selectFormatPattern 0 for key "gender_error"';
expect(result).to.equal("");
expect(loggerStub.warn.called).to.equal(true);
expect(loggerStub.warn.getCall(0).args[0]).to.equal(errMessage);

done();
});
Expand Down

0 comments on commit 40029e6

Please sign in to comment.