From 9e4295adf6b05584469d708e9d2c1a1e12a9a583 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 13:07:09 +0200 Subject: [PATCH 01/20] licence errors --- src/Cell.ts | 7 +++++-- src/i18n/enGB.ts | 3 ++- src/i18n/plPL.ts | 1 + src/interpreter/Interpreter.ts | 10 +++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Cell.ts b/src/Cell.ts index 4803de3265..8283db04aa 100644 --- a/src/Cell.ts +++ b/src/Cell.ts @@ -24,10 +24,13 @@ export enum ErrorType { /** Cyclic dependency. */ CYCLE = 'CYCLE', - /* Wrong address reference. */ + /** Wrong address reference. */ REF = 'REF', - /* Generic error */ + /** Invalid/missing licence error. */ + LIC = 'LIC', + + /** Generic error */ ERROR = 'ERROR' } diff --git a/src/i18n/enGB.ts b/src/i18n/enGB.ts index 6af858c317..9e8fc5be17 100644 --- a/src/i18n/enGB.ts +++ b/src/i18n/enGB.ts @@ -121,7 +121,8 @@ export const enGB: RawTranslationPackage = { NA: '#N/A', CYCLE: '#CYCLE!', REF: '#REF!', - ERROR: '#ERROR!' + ERROR: '#ERROR!', + LIC: '#LIC!', }, ui: { NEW_SHEET_PREFIX: 'Sheet', diff --git a/src/i18n/plPL.ts b/src/i18n/plPL.ts index 717fe5bda2..6903ade78f 100644 --- a/src/i18n/plPL.ts +++ b/src/i18n/plPL.ts @@ -122,6 +122,7 @@ export const plPL: RawTranslationPackage = { CYCLE: '#CYKL!', REF: '#ADR!', ERROR: '#BŁĄD!', + LIC: '#LIC!', }, ui: { NEW_SHEET_PREFIX: 'Arkusz', diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 23c308e668..f85a755bb1 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -10,17 +10,18 @@ import {ColumnSearchStrategy} from '../ColumnSearch/ColumnSearchStrategy' import {Config} from '../Config' import {DateTimeHelper} from '../DateTimeHelper' import {DependencyGraph} from '../DependencyGraph' +import {LicenseKeyValidityState} from '../helpers/licenseKeyValidator' import {Matrix, NotComputedMatrix} from '../Matrix' import {Maybe} from '../Maybe' +import {NamedExpressions} from '../NamedExpressions' +import {NumberLiteralHelper} from '../NumberLiteralHelper' // noinspection TypeScriptPreferShortImport import {Ast, AstNodeType, CellRangeAst, ColumnRangeAst, RowRangeAst} from '../parser/Ast' import {Statistics} from '../statistics/Statistics' import {ArithmeticHelper, divide, multiply, percent, power, unaryminus} from './ArithmeticHelper' +import {FunctionRegistry} from './FunctionRegistry' import {InterpreterValue, SimpleRangeValue} from './InterpreterValue' import {concatenate} from './text' -import {NumberLiteralHelper} from '../NumberLiteralHelper' -import {FunctionRegistry} from './FunctionRegistry' -import {NamedExpressions} from '../NamedExpressions' export class Interpreter { private gpu?: GPU.GPU @@ -47,6 +48,9 @@ export class Interpreter { * @param formulaAddress - address of the cell in which formula is located */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { + if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { + return new CellError(ErrorType.LIC) + } switch (ast.type) { case AstNodeType.EMPTY: { throw new Error('Empty argument should not be evaluated.') From f17eea67b2a1c92fe660c0e73efa0dacdcc83ff8 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 13:33:13 +0200 Subject: [PATCH 02/20] linter --- src/i18n/languages/enGB.ts | 2 +- src/i18n/languages/plPL.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/i18n/languages/enGB.ts b/src/i18n/languages/enGB.ts index 7e217518ba..bfe31d1df2 100644 --- a/src/i18n/languages/enGB.ts +++ b/src/i18n/languages/enGB.ts @@ -10,12 +10,12 @@ export const enGB: RawTranslationPackage = { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', ERROR: '#ERROR!', + LIC: '#LIC!', NA: '#N/A', NAME: '#NAME?', NUM: '#NUM!', REF: '#REF!', VALUE: '#VALUE!', - LIC: '#LIC!', }, functions: { ABS: 'ABS', diff --git a/src/i18n/languages/plPL.ts b/src/i18n/languages/plPL.ts index 19af851c1a..03918dfb48 100644 --- a/src/i18n/languages/plPL.ts +++ b/src/i18n/languages/plPL.ts @@ -10,12 +10,12 @@ export const plPL: RawTranslationPackage = { CYCLE: '#CYKL!', DIV_BY_ZERO: '#DZIEL/0!', ERROR: '#BŁĄD!', + LIC: '#LIC!', NA: '#N/A', NAME: '#NAZWA?', NUM: '#LICZBA!', REF: '#ADR!', VALUE: '#ARG!', - LIC: '#LIC!', }, functions: { ABS: 'WART.BEZWGL', From e4858d38bce538ea473cf5666eb2800696689e75 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 13:55:36 +0200 Subject: [PATCH 03/20] tests --- src/Serialization.ts | 9 ++++++++- test/licence.spec.ts | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/licence.spec.ts diff --git a/src/Serialization.ts b/src/Serialization.ts index e38e9ee045..cef521e53a 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -3,10 +3,11 @@ * Copyright (c) 2020 Handsoncode. All rights reserved. */ -import {simpleCellAddress, SimpleCellAddress} from './Cell' +import {CellError, ErrorType, simpleCellAddress, SimpleCellAddress} from './Cell' import {CellValue, DetailedCellError, Exporter, NoErrorCellValue} from './CellValue' import {Config} from './Config' import {DependencyGraph, FormulaCellVertex, MatrixVertex, ParsingErrorVertex} from './DependencyGraph' +import {LicenseKeyValidityState} from './helpers/licenseKeyValidator' import {Maybe} from './Maybe' import {buildLexerConfig, Unparser} from './parser' import {NamedExpressions} from './NamedExpressions' @@ -21,6 +22,9 @@ export class Serialization { } public getCellFormula(address: SimpleCellAddress): Maybe { + if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { + return undefined + } const formulaVertex = this.dependencyGraph.getCell(address) if (formulaVertex instanceof FormulaCellVertex) { const formula = formulaVertex.getFormula(this.dependencyGraph.lazilyTransformingAstService) @@ -37,6 +41,9 @@ export class Serialization { } public getCellSerialized(address: SimpleCellAddress): NoErrorCellValue { + if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { + return this.config.translationPackage.getErrorTranslation(ErrorType.LIC) + } const formula: Maybe = this.getCellFormula(address) if (formula !== undefined) { return formula diff --git a/test/licence.spec.ts b/test/licence.spec.ts new file mode 100644 index 0000000000..4aaeb1b31e --- /dev/null +++ b/test/licence.spec.ts @@ -0,0 +1,15 @@ +import {ErrorType, HyperFormula} from '../src' +import {CellError} from '../src/Cell' +import {adr, detailedError} from './testUtils' + +describe( 'Wrong licence', () => { + it('eval', () => { + const engine = HyperFormula.buildFromArray([['=TRUE()']], {licenseKey: ''}) + expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC)) + }) + + it('serialization', () => { + const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1]], {licenseKey: ''}) + expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', '#LIC!', '#LIC!']]) + }) +}) From 9997990bfd65e3754b4f3635486f0a43d09b818d Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 13:59:37 +0200 Subject: [PATCH 04/20] syntax error --- test/licence.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/licence.spec.ts b/test/licence.spec.ts index 4aaeb1b31e..a56746cfb1 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -9,7 +9,7 @@ describe( 'Wrong licence', () => { }) it('serialization', () => { - const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1]], {licenseKey: ''}) - expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', '#LIC!', '#LIC!']]) + const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) + expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', '#LIC!', '#LIC!', '#LIC!']]) }) }) From 779198d11ab9fdae845d4a8f74f1562aa2f57c04 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 14:35:17 +0200 Subject: [PATCH 05/20] not in translation --- src/Serialization.ts | 2 +- src/interpreter/Interpreter.ts | 3 ++- test/licence.spec.ts | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index cef521e53a..955398255a 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -42,7 +42,7 @@ export class Serialization { public getCellSerialized(address: SimpleCellAddress): NoErrorCellValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return this.config.translationPackage.getErrorTranslation(ErrorType.LIC) + return '#LIC!' } const formula: Maybe = this.getCellFormula(address) if (formula !== undefined) { diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index f85a755bb1..837cdb3073 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -4,6 +4,7 @@ */ import GPU from 'gpu.js' +import {detailedError} from '../../test/testUtils' import {AbsoluteCellRange, AbsoluteColumnRange, AbsoluteRowRange} from '../AbsoluteCellRange' import {CellError, ErrorType, InternalNoErrorCellValue, invalidSimpleCellAddress, SimpleCellAddress} from '../Cell' import {ColumnSearchStrategy} from '../ColumnSearch/ColumnSearchStrategy' @@ -49,7 +50,7 @@ export class Interpreter { */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new CellError(ErrorType.LIC) + return detailedError(ErrorType.LIC, `license ${this.config.licenseKeyValidityState}`) } switch (ast.type) { case AstNodeType.EMPTY: { diff --git a/test/licence.spec.ts b/test/licence.spec.ts index a56746cfb1..6d08f02fae 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -5,7 +5,7 @@ import {adr, detailedError} from './testUtils' describe( 'Wrong licence', () => { it('eval', () => { const engine = HyperFormula.buildFromArray([['=TRUE()']], {licenseKey: ''}) - expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC)) + expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, 'license missing')) }) it('serialization', () => { From 77ae15831fe6cd50c1f851ffbc333a84186b4b6e Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 14:43:07 +0200 Subject: [PATCH 06/20] fixed compilation --- src/i18n/TranslationPackage.ts | 2 +- src/i18n/languages/csCZ.ts | 2 ++ src/i18n/languages/daDK.ts | 2 ++ src/i18n/languages/deDE.ts | 2 ++ src/i18n/languages/enGB.ts | 3 ++- src/i18n/languages/esES.ts | 2 ++ src/i18n/languages/fiFI.ts | 2 ++ src/i18n/languages/frFR.ts | 2 ++ src/i18n/languages/huHU.ts | 2 ++ src/i18n/languages/itIT.ts | 2 ++ src/i18n/languages/nbNO.ts | 2 ++ src/i18n/languages/nlNL.ts | 2 ++ src/i18n/languages/plPL.ts | 3 ++- src/i18n/languages/ptPT.ts | 2 ++ src/i18n/languages/ruRU.ts | 2 ++ src/i18n/languages/svSE.ts | 2 ++ src/i18n/languages/trTR.ts | 2 ++ 17 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index 33a22706fe..e3f07ffc93 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -91,7 +91,7 @@ export class TranslationPackage { } private checkErrors(): void { for(const key of Object.values(ErrorType)){ - if(! (key in this.errors)){ + if(! (key in this.errors) && (key !== 'LIC')){ throw new MissingTranslationError(`errors.${key}`) } } diff --git a/src/i18n/languages/csCZ.ts b/src/i18n/languages/csCZ.ts index 6dadf015e1..037fd96072 100644 --- a/src/i18n/languages/csCZ.ts +++ b/src/i18n/languages/csCZ.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const csCZ: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DĚLENÍ_NULOU!', diff --git a/src/i18n/languages/daDK.ts b/src/i18n/languages/daDK.ts index e704d402bf..eefeb9036f 100644 --- a/src/i18n/languages/daDK.ts +++ b/src/i18n/languages/daDK.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const daDK: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIVISION/0!', diff --git a/src/i18n/languages/deDE.ts b/src/i18n/languages/deDE.ts index 84b4a82099..fe2f79e002 100644 --- a/src/i18n/languages/deDE.ts +++ b/src/i18n/languages/deDE.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const deDE: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/enGB.ts b/src/i18n/languages/enGB.ts index bfe31d1df2..5bfe4024d6 100644 --- a/src/i18n/languages/enGB.ts +++ b/src/i18n/languages/enGB.ts @@ -6,11 +6,12 @@ import {RawTranslationPackage} from '..' export const enGB: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', ERROR: '#ERROR!', - LIC: '#LIC!', NA: '#N/A', NAME: '#NAME?', NUM: '#NUM!', diff --git a/src/i18n/languages/esES.ts b/src/i18n/languages/esES.ts index 186e14f90a..e382d9a487 100644 --- a/src/i18n/languages/esES.ts +++ b/src/i18n/languages/esES.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const esES: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#¡DIV/0!', diff --git a/src/i18n/languages/fiFI.ts b/src/i18n/languages/fiFI.ts index 37439ff115..0325105b18 100644 --- a/src/i18n/languages/fiFI.ts +++ b/src/i18n/languages/fiFI.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const fiFI: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#JAKO/0!', diff --git a/src/i18n/languages/frFR.ts b/src/i18n/languages/frFR.ts index 7881d0f4d0..8c73f0703a 100644 --- a/src/i18n/languages/frFR.ts +++ b/src/i18n/languages/frFR.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const frFR: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/huHU.ts b/src/i18n/languages/huHU.ts index e0b1c9f7d3..e63a1c5c21 100644 --- a/src/i18n/languages/huHU.ts +++ b/src/i18n/languages/huHU.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const huHU: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#ZÉRÓOSZTÓ!', diff --git a/src/i18n/languages/itIT.ts b/src/i18n/languages/itIT.ts index 7c09680895..f47dc05897 100644 --- a/src/i18n/languages/itIT.ts +++ b/src/i18n/languages/itIT.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const itIT: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/nbNO.ts b/src/i18n/languages/nbNO.ts index 00230a6855..096ebe05a8 100644 --- a/src/i18n/languages/nbNO.ts +++ b/src/i18n/languages/nbNO.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const nbNO: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/nlNL.ts b/src/i18n/languages/nlNL.ts index 57c78d77ce..242f8206d1 100644 --- a/src/i18n/languages/nlNL.ts +++ b/src/i18n/languages/nlNL.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const nlNL: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DELING.DOOR.0!', diff --git a/src/i18n/languages/plPL.ts b/src/i18n/languages/plPL.ts index 03918dfb48..e09af46e26 100644 --- a/src/i18n/languages/plPL.ts +++ b/src/i18n/languages/plPL.ts @@ -6,11 +6,12 @@ import {RawTranslationPackage} from '..' export const plPL: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYKL!', DIV_BY_ZERO: '#DZIEL/0!', ERROR: '#BŁĄD!', - LIC: '#LIC!', NA: '#N/A', NAME: '#NAZWA?', NUM: '#LICZBA!', diff --git a/src/i18n/languages/ptPT.ts b/src/i18n/languages/ptPT.ts index b71b826b61..ea4d12698b 100644 --- a/src/i18n/languages/ptPT.ts +++ b/src/i18n/languages/ptPT.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const ptPT: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/ruRU.ts b/src/i18n/languages/ruRU.ts index 6356f79f68..94c9a2f53c 100644 --- a/src/i18n/languages/ruRU.ts +++ b/src/i18n/languages/ruRU.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const ruRU: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#ДЕЛ/0!', diff --git a/src/i18n/languages/svSE.ts b/src/i18n/languages/svSE.ts index 91a03c5ee7..703636f9ac 100644 --- a/src/i18n/languages/svSE.ts +++ b/src/i18n/languages/svSE.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const svSE: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIVISION/0!', diff --git a/src/i18n/languages/trTR.ts b/src/i18n/languages/trTR.ts index 1f19bed94f..05e4f68f09 100644 --- a/src/i18n/languages/trTR.ts +++ b/src/i18n/languages/trTR.ts @@ -6,6 +6,8 @@ import {RawTranslationPackage} from '..' export const trTR: RawTranslationPackage = { + // eslint-disable-next-line + // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#SAYI/0!', From 9bcc843a17e4acc5af14e01d6bbf412b32da6810 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 4 Jun 2020 14:53:25 +0200 Subject: [PATCH 07/20] error translations --- src/i18n/TranslationPackage.ts | 3 +++ src/interpreter/Interpreter.ts | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index e3f07ffc93..a6a86dc89a 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -65,6 +65,9 @@ export class TranslationPackage { } public getErrorTranslation(key: ErrorType): string { + if(key === ErrorType.LIC) { + return '#LIC!' + } const val = this.errors[key] if(val === undefined) { throw new MissingTranslationError(`errors.${key}`) diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 837cdb3073..7d08a483c2 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -4,7 +4,6 @@ */ import GPU from 'gpu.js' -import {detailedError} from '../../test/testUtils' import {AbsoluteCellRange, AbsoluteColumnRange, AbsoluteRowRange} from '../AbsoluteCellRange' import {CellError, ErrorType, InternalNoErrorCellValue, invalidSimpleCellAddress, SimpleCellAddress} from '../Cell' import {ColumnSearchStrategy} from '../ColumnSearch/ColumnSearchStrategy' @@ -50,7 +49,7 @@ export class Interpreter { */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return detailedError(ErrorType.LIC, `license ${this.config.licenseKeyValidityState}`) + return new CellError(ErrorType.LIC, `license ${this.config.licenseKeyValidityState}`) } switch (ast.type) { case AstNodeType.EMPTY: { From 7eb3b177f7ae397af797582253d68dd332e1e18d Mon Sep 17 00:00:00 2001 From: izulin Date: Fri, 5 Jun 2020 00:44:10 +0200 Subject: [PATCH 08/20] lic test --- test/parser/error-literals.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/parser/error-literals.spec.ts b/test/parser/error-literals.spec.ts index 94569ffb08..17228e5277 100644 --- a/test/parser/error-literals.spec.ts +++ b/test/parser/error-literals.spec.ts @@ -14,6 +14,13 @@ describe('Parsing error literals', () => { expect(ast.error.type).toEqual(ErrorType.VALUE) }) + it('should not parse #LIC! as license error', () => { + const parser = buildEmptyParserWithCaching(new Config()) + const ast = parser.parse('=#LIC!', simpleCellAddress(0, 0, 0)).ast as ErrorAst + expect(ast.type).toBe(AstNodeType.ERROR) + expect(ast.error.type).toEqual(ErrorType.ERROR) + }) + it('should parse error literals with ?', () => { const parser = buildEmptyParserWithCaching(new Config()) const ast = parser.parse('=#NAME?', simpleCellAddress(0, 0, 0)).ast as ErrorAst From b3f93fac5f42252790876ef4421aebff2d1c4ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= <40573492+izulin@users.noreply.github.com> Date: Sun, 7 Jun 2020 15:33:59 +0200 Subject: [PATCH 09/20] Update src/i18n/TranslationPackage.ts Co-authored-by: Wojciech Czerniak --- src/i18n/TranslationPackage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index a6a86dc89a..ea9042f362 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -94,7 +94,7 @@ export class TranslationPackage { } private checkErrors(): void { for(const key of Object.values(ErrorType)){ - if(! (key in this.errors) && (key !== 'LIC')){ + if(! (key in this.errors) && (key !== ErrorType.LIC)){ throw new MissingTranslationError(`errors.${key}`) } } From b710ab38b158f11bb0e658884dc704a9b5c4bd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= <40573492+izulin@users.noreply.github.com> Date: Sun, 7 Jun 2020 15:34:27 +0200 Subject: [PATCH 10/20] Update src/interpreter/Interpreter.ts Co-authored-by: Wojciech Czerniak --- src/interpreter/Interpreter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 7d08a483c2..1d82ba9584 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -49,7 +49,7 @@ export class Interpreter { */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new CellError(ErrorType.LIC, `license ${this.config.licenseKeyValidityState}`) + return new CellError(ErrorType.LIC, `License key is ${this.config.licenseKeyValidityState}.`) } switch (ast.type) { case AstNodeType.EMPTY: { From f561a969761764cee4df04a29a0e12ef65adb123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= <40573492+izulin@users.noreply.github.com> Date: Sun, 7 Jun 2020 15:34:38 +0200 Subject: [PATCH 11/20] Update src/i18n/TranslationPackage.ts Co-authored-by: Wojciech Czerniak --- src/i18n/TranslationPackage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index ea9042f362..67f9817a39 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -66,7 +66,7 @@ export class TranslationPackage { public getErrorTranslation(key: ErrorType): string { if(key === ErrorType.LIC) { - return '#LIC!' + return `#${ErrorType.LIC}!` } const val = this.errors[key] if(val === undefined) { From 91035501287524fe5a47cb4aa3dc6bf6e9fd9d8d Mon Sep 17 00:00:00 2001 From: izulin Date: Sun, 7 Jun 2020 16:10:47 +0200 Subject: [PATCH 12/20] typing --- src/Cell.ts | 2 ++ src/Config.ts | 4 ++-- src/i18n/TranslationPackage.ts | 8 ++++---- src/i18n/index.ts | 4 ++-- src/parser/ParserConfig.ts | 4 ++-- test/licence.spec.ts | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Cell.ts b/src/Cell.ts index 8283db04aa..5cd7f8cb98 100644 --- a/src/Cell.ts +++ b/src/Cell.ts @@ -34,6 +34,8 @@ export enum ErrorType { ERROR = 'ERROR' } +export type TranslatableErrorType = Exclude + export const EmptyValue = Symbol('Empty value') export type EmptyValueType = typeof EmptyValue export type InternalNoErrorCellValue = number | string | boolean | EmptyValueType diff --git a/src/Config.ts b/src/Config.ts index e244eb20a6..7217040e86 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -3,7 +3,7 @@ * Copyright (c) 2020 Handsoncode. All rights reserved. */ -import {ErrorType} from './Cell' +import {ErrorType, TranslatableErrorType} from './Cell' import {defaultParseToDateTime} from './DateTimeDefault' import {DateTime, instanceOfSimpleDate, SimpleDate, SimpleDateTime, SimpleTime} from './DateTimeHelper' import { @@ -451,7 +451,7 @@ export class Config implements ConfigParams, ParserConfig { * * @internal */ - public readonly errorMapping: Record + public readonly errorMapping: Record /** @inheritDoc */ public readonly maxRows: number /** @inheritDoc */ diff --git a/src/i18n/TranslationPackage.ts b/src/i18n/TranslationPackage.ts index 67f9817a39..83cb759e21 100644 --- a/src/i18n/TranslationPackage.ts +++ b/src/i18n/TranslationPackage.ts @@ -3,7 +3,7 @@ * Copyright (c) 2020 Handsoncode. All rights reserved. */ -import {ErrorType} from '../Cell' +import {ErrorType, TranslatableErrorType} from '../Cell' import {MissingTranslationError} from '../errors' import {ErrorTranslationSet, TranslationSet, UIElement, UITranslationSet} from './index' @@ -34,11 +34,11 @@ export class TranslationPackage { }, {} as Record) } - public buildErrorMapping(): Record { + public buildErrorMapping(): Record { return Object.keys(this.errors).reduce((ret, key) => { - ret[this.errors[key as ErrorType]] = key as ErrorType + ret[this.errors[key as TranslatableErrorType]] = key as TranslatableErrorType return ret - }, {} as Record) + }, {} as Record) } public isFunctionTranslated(key: string): boolean { diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 13d73d33ce..27cc4284e8 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -3,14 +3,14 @@ * Copyright (c) 2020 Handsoncode. All rights reserved. */ -import {ErrorType} from '../Cell' +import {TranslatableErrorType} from '../Cell' import {enGB} from './languages/enGB' import {plPL} from './languages/plPL' import {buildTranslationPackage, RawTranslationPackage, TranslationPackage} from './TranslationPackage' export type TranslationSet = Record export type UITranslationSet = Record -export type ErrorTranslationSet = Record +export type ErrorTranslationSet = Record export {plPL} from './languages/plPL' export {enGB} from './languages/enGB' export {RawTranslationPackage, TranslationPackage, buildTranslationPackage} diff --git a/src/parser/ParserConfig.ts b/src/parser/ParserConfig.ts index 489ec24e48..44a0d592c0 100644 --- a/src/parser/ParserConfig.ts +++ b/src/parser/ParserConfig.ts @@ -3,14 +3,14 @@ * Copyright (c) 2020 Handsoncode. All rights reserved. */ -import {ErrorType} from '../Cell' +import {ErrorType, TranslatableErrorType} from '../Cell' import {TranslationPackage} from '../i18n' export interface ParserConfig { functionArgSeparator: string, decimalSeparator: '.' | ',', translationPackage: TranslationPackage, - errorMapping: Record, + errorMapping: Record, maxColumns: number, maxRows: number, } diff --git a/test/licence.spec.ts b/test/licence.spec.ts index 6d08f02fae..ffbae1e8d2 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -5,7 +5,7 @@ import {adr, detailedError} from './testUtils' describe( 'Wrong licence', () => { it('eval', () => { const engine = HyperFormula.buildFromArray([['=TRUE()']], {licenseKey: ''}) - expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, 'license missing')) + expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) }) it('serialization', () => { From 7bab799c747444b9f32d90fb12a89674832d7000 Mon Sep 17 00:00:00 2001 From: izulin Date: Sun, 7 Jun 2020 16:14:10 +0200 Subject: [PATCH 13/20] typing restored --- src/i18n/languages/csCZ.ts | 2 -- src/i18n/languages/daDK.ts | 2 -- src/i18n/languages/deDE.ts | 2 -- src/i18n/languages/enGB.ts | 2 -- src/i18n/languages/esES.ts | 2 -- src/i18n/languages/fiFI.ts | 2 -- src/i18n/languages/frFR.ts | 2 -- src/i18n/languages/huHU.ts | 2 -- src/i18n/languages/itIT.ts | 2 -- src/i18n/languages/nbNO.ts | 2 -- src/i18n/languages/nlNL.ts | 2 -- src/i18n/languages/plPL.ts | 2 -- src/i18n/languages/ptPT.ts | 2 -- src/i18n/languages/ruRU.ts | 2 -- src/i18n/languages/svSE.ts | 2 -- src/i18n/languages/trTR.ts | 2 -- 16 files changed, 32 deletions(-) diff --git a/src/i18n/languages/csCZ.ts b/src/i18n/languages/csCZ.ts index 037fd96072..6dadf015e1 100644 --- a/src/i18n/languages/csCZ.ts +++ b/src/i18n/languages/csCZ.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const csCZ: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DĚLENÍ_NULOU!', diff --git a/src/i18n/languages/daDK.ts b/src/i18n/languages/daDK.ts index eefeb9036f..e704d402bf 100644 --- a/src/i18n/languages/daDK.ts +++ b/src/i18n/languages/daDK.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const daDK: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIVISION/0!', diff --git a/src/i18n/languages/deDE.ts b/src/i18n/languages/deDE.ts index fe2f79e002..84b4a82099 100644 --- a/src/i18n/languages/deDE.ts +++ b/src/i18n/languages/deDE.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const deDE: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/enGB.ts b/src/i18n/languages/enGB.ts index 5bfe4024d6..dd17c1f032 100644 --- a/src/i18n/languages/enGB.ts +++ b/src/i18n/languages/enGB.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const enGB: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/esES.ts b/src/i18n/languages/esES.ts index e382d9a487..186e14f90a 100644 --- a/src/i18n/languages/esES.ts +++ b/src/i18n/languages/esES.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const esES: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#¡DIV/0!', diff --git a/src/i18n/languages/fiFI.ts b/src/i18n/languages/fiFI.ts index 0325105b18..37439ff115 100644 --- a/src/i18n/languages/fiFI.ts +++ b/src/i18n/languages/fiFI.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const fiFI: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#JAKO/0!', diff --git a/src/i18n/languages/frFR.ts b/src/i18n/languages/frFR.ts index 8c73f0703a..7881d0f4d0 100644 --- a/src/i18n/languages/frFR.ts +++ b/src/i18n/languages/frFR.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const frFR: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/huHU.ts b/src/i18n/languages/huHU.ts index e63a1c5c21..e0b1c9f7d3 100644 --- a/src/i18n/languages/huHU.ts +++ b/src/i18n/languages/huHU.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const huHU: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#ZÉRÓOSZTÓ!', diff --git a/src/i18n/languages/itIT.ts b/src/i18n/languages/itIT.ts index f47dc05897..7c09680895 100644 --- a/src/i18n/languages/itIT.ts +++ b/src/i18n/languages/itIT.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const itIT: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/nbNO.ts b/src/i18n/languages/nbNO.ts index 096ebe05a8..00230a6855 100644 --- a/src/i18n/languages/nbNO.ts +++ b/src/i18n/languages/nbNO.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const nbNO: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/nlNL.ts b/src/i18n/languages/nlNL.ts index 242f8206d1..57c78d77ce 100644 --- a/src/i18n/languages/nlNL.ts +++ b/src/i18n/languages/nlNL.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const nlNL: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DELING.DOOR.0!', diff --git a/src/i18n/languages/plPL.ts b/src/i18n/languages/plPL.ts index e09af46e26..4370ce0bec 100644 --- a/src/i18n/languages/plPL.ts +++ b/src/i18n/languages/plPL.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const plPL: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYKL!', DIV_BY_ZERO: '#DZIEL/0!', diff --git a/src/i18n/languages/ptPT.ts b/src/i18n/languages/ptPT.ts index ea4d12698b..b71b826b61 100644 --- a/src/i18n/languages/ptPT.ts +++ b/src/i18n/languages/ptPT.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const ptPT: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIV/0!', diff --git a/src/i18n/languages/ruRU.ts b/src/i18n/languages/ruRU.ts index 94c9a2f53c..6356f79f68 100644 --- a/src/i18n/languages/ruRU.ts +++ b/src/i18n/languages/ruRU.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const ruRU: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#ДЕЛ/0!', diff --git a/src/i18n/languages/svSE.ts b/src/i18n/languages/svSE.ts index 703636f9ac..91a03c5ee7 100644 --- a/src/i18n/languages/svSE.ts +++ b/src/i18n/languages/svSE.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const svSE: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#DIVISION/0!', diff --git a/src/i18n/languages/trTR.ts b/src/i18n/languages/trTR.ts index 05e4f68f09..1f19bed94f 100644 --- a/src/i18n/languages/trTR.ts +++ b/src/i18n/languages/trTR.ts @@ -6,8 +6,6 @@ import {RawTranslationPackage} from '..' export const trTR: RawTranslationPackage = { - // eslint-disable-next-line - // @ts-ignore errors: { CYCLE: '#CYCLE!', DIV_BY_ZERO: '#SAYI/0!', From 5ec71cda2c0c81ba1016eada035e206c3c3e151d Mon Sep 17 00:00:00 2001 From: izulin Date: Sun, 7 Jun 2020 19:23:07 +0200 Subject: [PATCH 14/20] . --- src/Serialization.ts | 3 +++ test/licence.spec.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index 955398255a..1bbec1df53 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -58,6 +58,9 @@ export class Serialization { } public getCellValue(address: SimpleCellAddress): CellValue { + if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { + return new DetailedCellError(new CellError(ErrorType.LIC, `License key is ${this.config.licenseKeyValidityState}.`), `#${ErrorType.LIC}!`) + } return this.exporter.exportValue(this.dependencyGraph.getScalarValue(address)) } diff --git a/test/licence.spec.ts b/test/licence.spec.ts index ffbae1e8d2..843fc1fad3 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -4,8 +4,11 @@ import {adr, detailedError} from './testUtils' describe( 'Wrong licence', () => { it('eval', () => { - const engine = HyperFormula.buildFromArray([['=TRUE()']], {licenseKey: ''}) + const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) + expect(engine.getCellValue(adr('B1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) + expect(engine.getCellValue(adr('C1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) + expect(engine.getCellValue(adr('D1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) }) it('serialization', () => { From a121f0335bd907853bfd3d2002994398c0e20630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Uzna=C5=84ski?= <40573492+izulin@users.noreply.github.com> Date: Mon, 8 Jun 2020 23:53:42 +0200 Subject: [PATCH 15/20] Update src/Serialization.ts Co-authored-by: Wojciech Czerniak --- src/Serialization.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index 1bbec1df53..fdb64253ff 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -42,7 +42,7 @@ export class Serialization { public getCellSerialized(address: SimpleCellAddress): NoErrorCellValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return '#LIC!' + return `#${ErrorType.LIC}!` } const formula: Maybe = this.getCellFormula(address) if (formula !== undefined) { From bf2de10672fe32cb0910ef275a318941a146cab0 Mon Sep 17 00:00:00 2001 From: izulin Date: Thu, 10 Sep 2020 21:10:06 +0200 Subject: [PATCH 16/20] error messages --- src/Serialization.ts | 3 ++- src/error-message.ts | 1 + src/interpreter/Interpreter.ts | 2 +- test/licence.spec.ts | 9 +++++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index 9edd8da7e6..34e9794aa0 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -7,6 +7,7 @@ import {CellError, ErrorType, simpleCellAddress, SimpleCellAddress} from './Cell import {CellValue, DetailedCellError, Exporter, NoErrorCellValue} from './CellValue' import {Config} from './Config' import {DependencyGraph, FormulaCellVertex, MatrixVertex, ParsingErrorVertex} from './DependencyGraph' +import {ErrorMessage} from './error-message' import {LicenseKeyValidityState} from './helpers/licenseKeyValidator' import {Maybe} from './Maybe' import {buildLexerConfig, Unparser} from './parser' @@ -59,7 +60,7 @@ export class Serialization { public getCellValue(address: SimpleCellAddress): CellValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new DetailedCellError(new CellError(ErrorType.LIC, `License key is ${this.config.licenseKeyValidityState}.`), `#${ErrorType.LIC}!`) + return new DetailedCellError(new CellError(ErrorType.LIC, ErrorMessage.LicenseKey(this.config.licenseKeyValidityState)), `#${ErrorType.LIC}!`) } return this.exporter.exportValue(this.dependencyGraph.getScalarValue(address)) } diff --git a/src/error-message.ts b/src/error-message.ts index 2fbe1c40f5..c4c38ffd37 100644 --- a/src/error-message.ts +++ b/src/error-message.ts @@ -61,4 +61,5 @@ export class ErrorMessage { public static NonZero = 'Argument cannot be 0.' public static FunctionName = (arg: string) => `Function name ${arg} not recognized.` public static NamedExpressionName = (arg: string) => `Named expression ${arg} not recognized.` + public static LicenseKey = (arg: string) => `License key is ${arg}.` } diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 0117d5b48d..53c2e8cf0e 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -61,7 +61,7 @@ export class Interpreter { */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new CellError(ErrorType.LIC, `License key is ${this.config.licenseKeyValidityState}.`) + return new CellError(ErrorType.LIC, ErrorMessage.LicenseKey(this.config.licenseKeyValidityState)) } switch (ast.type) { case AstNodeType.EMPTY: { diff --git a/test/licence.spec.ts b/test/licence.spec.ts index 843fc1fad3..8e2a15b588 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -1,14 +1,15 @@ import {ErrorType, HyperFormula} from '../src' import {CellError} from '../src/Cell' +import {ErrorMessage} from '../src/error-message' import {adr, detailedError} from './testUtils' describe( 'Wrong licence', () => { it('eval', () => { const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) - expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) - expect(engine.getCellValue(adr('B1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) - expect(engine.getCellValue(adr('C1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) - expect(engine.getCellValue(adr('D1'))).toEqual(detailedError(ErrorType.LIC, 'License key is missing.')) + expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) + expect(engine.getCellValue(adr('B1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) + expect(engine.getCellValue(adr('C1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) + expect(engine.getCellValue(adr('D1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) }) it('serialization', () => { From 99531f0f4e7b914f7ed9894e83862fae1f484504 Mon Sep 17 00:00:00 2001 From: izulin Date: Fri, 11 Sep 2020 10:19:39 +0200 Subject: [PATCH 17/20] correct logic --- src/Serialization.ts | 6 ------ src/interpreter/FunctionRegistry.ts | 4 ++-- src/interpreter/Interpreter.ts | 6 +++--- test/licence.spec.ts | 8 ++++---- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index 34e9794aa0..73ca5eebd2 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -42,9 +42,6 @@ export class Serialization { } public getCellSerialized(address: SimpleCellAddress): NoErrorCellValue { - if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return `#${ErrorType.LIC}!` - } const formula: Maybe = this.getCellFormula(address) if (formula !== undefined) { return formula @@ -59,9 +56,6 @@ export class Serialization { } public getCellValue(address: SimpleCellAddress): CellValue { - if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new DetailedCellError(new CellError(ErrorType.LIC, ErrorMessage.LicenseKey(this.config.licenseKeyValidityState)), `#${ErrorType.LIC}!`) - } return this.exporter.exportValue(this.dependencyGraph.getScalarValue(address)) } diff --git a/src/interpreter/FunctionRegistry.ts b/src/interpreter/FunctionRegistry.ts index 34a5123f50..77a6e7a328 100644 --- a/src/interpreter/FunctionRegistry.ts +++ b/src/interpreter/FunctionRegistry.ts @@ -116,7 +116,7 @@ export class FunctionRegistry { } } - private static functionIsProtected(functionId: string) { + public static functionIsProtected(functionId: string) { return this._protectedPlugins.has(functionId) } @@ -224,4 +224,4 @@ export class FunctionRegistry { this.structuralChangeFunctions.add(functionId) } } -} \ No newline at end of file +} diff --git a/src/interpreter/Interpreter.ts b/src/interpreter/Interpreter.ts index 53c2e8cf0e..1667de853b 100644 --- a/src/interpreter/Interpreter.ts +++ b/src/interpreter/Interpreter.ts @@ -60,9 +60,6 @@ export class Interpreter { * @param formulaAddress - address of the cell in which formula is located */ public evaluateAst(ast: Ast, formulaAddress: SimpleCellAddress): InterpreterValue { - if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return new CellError(ErrorType.LIC, ErrorMessage.LicenseKey(this.config.licenseKeyValidityState)) - } switch (ast.type) { case AstNodeType.EMPTY: { return EmptyValue @@ -198,6 +195,9 @@ export class Interpreter { } } case AstNodeType.FUNCTION_CALL: { + if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID && !FunctionRegistry.functionIsProtected(ast.procedureName)) { + return new CellError(ErrorType.LIC, ErrorMessage.LicenseKey(this.config.licenseKeyValidityState)) + } const pluginEntry = this.functionRegistry.getFunction(ast.procedureName) if (pluginEntry && this.config.translationPackage.isFunctionTranslated(ast.procedureName)) { const [pluginFunction, pluginInstance] = pluginEntry as [string, any] diff --git a/test/licence.spec.ts b/test/licence.spec.ts index 8e2a15b588..e64ca6e23f 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -7,13 +7,13 @@ describe( 'Wrong licence', () => { it('eval', () => { const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) expect(engine.getCellValue(adr('A1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) - expect(engine.getCellValue(adr('B1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) - expect(engine.getCellValue(adr('C1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) - expect(engine.getCellValue(adr('D1'))).toEqual(detailedError(ErrorType.LIC, ErrorMessage.LicenseKey('missing'))) + expect(engine.getCellValue(adr('B1'))).toEqual(null) + expect(engine.getCellValue(adr('C1'))).toEqual(1) + expect(engine.getCellValue(adr('D1'))).toEqual(detailedError(ErrorType.ERROR, ErrorMessage.ParseError)) }) it('serialization', () => { const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) - expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', '#LIC!', '#LIC!', '#LIC!']]) + expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', null, 1, '#ERROR!']]) }) }) From 4f21ce233dfdd608a2c1fb790366c095ef954903 Mon Sep 17 00:00:00 2001 From: izulin Date: Fri, 11 Sep 2020 10:20:58 +0200 Subject: [PATCH 18/20] doc --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7f70147bb..d3a578e02e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added 6 engineering functions: OCT2BIN, OCT2DEC, OCT2HEX, HEX2BIN, HEX2OCT, HEX2DEC. (#497) - Added a configuration option to evaluate reference to an empty cells as a zero. (#476) - Added detailed error messages for error values (#506). +- Added new error type: missing licence. (#306) ### Changed - Operation `moveCells` creating cyclic dependencies does not cause losing original formula. (#479) From 373cc224049882e3f36a0bbc0e186e1fda30911b Mon Sep 17 00:00:00 2001 From: izulin Date: Fri, 11 Sep 2020 12:38:38 +0200 Subject: [PATCH 19/20] . --- src/Serialization.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Serialization.ts b/src/Serialization.ts index 73ca5eebd2..94868b7f67 100644 --- a/src/Serialization.ts +++ b/src/Serialization.ts @@ -23,9 +23,6 @@ export class Serialization { } public getCellFormula(address: SimpleCellAddress): Maybe { - if(this.config.licenseKeyValidityState !== LicenseKeyValidityState.VALID) { - return undefined - } const formulaVertex = this.dependencyGraph.getCell(address) if (formulaVertex instanceof FormulaCellVertex) { const formula = formulaVertex.getFormula(this.dependencyGraph.lazilyTransformingAstService) From 7fb55c9686ac2f4970d64b959fc2c201ab5af7c1 Mon Sep 17 00:00:00 2001 From: izulin Date: Fri, 11 Sep 2020 13:03:49 +0200 Subject: [PATCH 20/20] . --- test/licence.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/licence.spec.ts b/test/licence.spec.ts index e64ca6e23f..c34ff1ebd8 100644 --- a/test/licence.spec.ts +++ b/test/licence.spec.ts @@ -14,6 +14,6 @@ describe( 'Wrong licence', () => { it('serialization', () => { const engine = HyperFormula.buildFromArray([['=TRUE()', null, 1, '=A(']], {licenseKey: ''}) - expect(engine.getSheetSerialized(0)).toEqual([['#LIC!', null, 1, '#ERROR!']]) + expect(engine.getSheetSerialized(0)).toEqual([['=TRUE()', null, 1, '=A(']]) }) })