Skip to content

Commit

Permalink
fix: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Dec 14, 2020
1 parent 7fdfb00 commit 160c6fc
Show file tree
Hide file tree
Showing 11 changed files with 1,364 additions and 1,336 deletions.
11 changes: 2 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
],
ignorePatterns: ['.eslintrc.js'],
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
Expand All @@ -30,20 +31,12 @@ module.exports = {
env: {
jest: true,
},
extends: ['plugin:jest/recommended'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-alias-methods': 'error',
'jest/no-identical-title': 'error',
'jest/no-jasmine-globals': 'error',
'jest/no-jest-import': 'error',
'jest/no-test-prefixes': 'error',
'jest/no-test-callback': 'error',
'jest/no-test-return-statement': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/prefer-spy-on': 'error',
'jest/valid-expect': 'error',
},
},
],
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
},
"homepage": "https://github.com/armano2/freemarker-parser#readme",
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.19",
"@types/node": "^14.14.10",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.6.0",
"@types/node": "^14.14.13",
"@typescript-eslint/eslint-plugin": "^4.10.0",
"@typescript-eslint/parser": "^4.10.0",
"eslint": "^7.15.0",
"eslint-plugin-jest": "^24.1.3",
"glob": "^7.1.6",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"ts-jest": "^25.1.0",
"typescript": "^4.1.2"
"jest": "^26.6.3",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
},
"dependencies": {}
}
6 changes: 4 additions & 2 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ export class Parser extends ParserLocation {
case NodeType.CloseDirective:
case NodeType.OpenDirective:
if (token.text in Directives) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return Directives[token.text as any] as NodeTypes;
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
return (Directives[
token.text as keyof typeof Directives
] as unknown) as NodeTypes;
}
break;
case NodeType.Interpolation:
Expand Down
2 changes: 1 addition & 1 deletion src/enum/Operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const BinaryOps: Record<string, number> = {
} as const;

// Get return the longest key length of any object
export function getMaxKeyLength(obj: object): number {
export function getMaxKeyLength<T>(obj: T): number {
let maxLen = 0;
let len;
for (const key of Object.keys(obj)) {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/Chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export function isWhitespace(ch: number): boolean {
export function isIdentifierStart(ch: number): boolean {
return (
(isLetter(ch) ||
ch === ECharCodes.$ ||
ch === ECharCodes.Underscore || // `$` and `_`
ch === ECharCodes.$ ||
ch === ECharCodes.Underscore || // `$` and `_`
ch >= 128) &&
!BinaryOps[String.fromCharCode(ch)]
);
Expand All @@ -36,9 +36,9 @@ export function isIdentifierStart(ch: number): boolean {
export function isIdentifierPart(ch: number): boolean {
return (
(isLetter(ch) ||
isDecimalDigit(ch) ||
ch === ECharCodes.$ ||
ch === ECharCodes.Underscore || // `$` and `_`
isDecimalDigit(ch) ||
ch === ECharCodes.$ ||
ch === ECharCodes.Underscore || // `$` and `_`
ch >= 128) &&
!BinaryOps[String.fromCharCode(ch)]
);
Expand Down
12 changes: 8 additions & 4 deletions src/utils/Params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ export function paramParser(token: Token): AllParamTypes | undefined {
try {
return parser.parseExpressions();
} catch (e) {
throw new ParseError(e.message, {
start: token.start + e.start,
end: token.start + e.end,
});
if (e instanceof ParseError) {
throw new ParseError(e.message, {
start: token.start + e.start,
end: token.start + e.end,
});
} else {
throw e;
}
}
} else {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/tokenizer-invalid.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`errors missing close tag in directive 1`] = `"OpenDirective name cannot

exports[`errors missing close tag in macro 1`] = `"OpenMacro name cannot be empty [2-2]"`;

exports[`errors unclosed comment 1`] = `"Unclosed comment [undefined-undefined]"`;
exports[`errors unclosed comment 1`] = `"Unclosed comment"`;

exports[`unclosed directive 1`] = `"Unclosed directive or macro [5-6]"`;

Expand Down
40 changes: 20 additions & 20 deletions test/parser-invalid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ const parser = new Parser();

const testsPath = path.join(__dirname, 'resource', 'invalid');

const files = glob.sync('./**/*.ftl', {
cwd: testsPath,
nodir: true,
absolute: true,
});
const files = glob
.sync('./**/*.ftl', {
cwd: testsPath,
nodir: true,
absolute: true,
})
.map((file) => [path.basename(file), file]);

for (const file of files) {
describe(path.basename(file), () => {
const template = fs.readFileSync(file, 'utf8');
const data = parser.parse(template);
describe.each(files)('%s', (_, file) => {
const template = fs.readFileSync(file, 'utf8');
const data = parser.parse(template);

it('should have errors', () => {
expect(data.ast.errors).toBeTruthy();
expect(data.ast.errors).toMatchSnapshot();
});
it('should have errors', () => {
expect(data.ast.errors).toBeTruthy();
expect(data.ast.errors).toMatchSnapshot();
});

it('should have correct tokens', () => {
expect(data.tokens).toMatchSnapshot();
});
it('should have correct tokens', () => {
expect(data.tokens).toMatchSnapshot();
});

it('should have correct ast', () => {
expect(data.ast).toMatchSnapshot();
});
it('should have correct ast', () => {
expect(data.ast).toMatchSnapshot();
});
}
});
38 changes: 19 additions & 19 deletions test/parser-valid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ const parser = new Parser();

const testsPath = path.join(__dirname, 'resource', 'valid');

const files = glob.sync('./**/*.ftl', {
cwd: testsPath,
nodir: true,
absolute: true,
});
const files = glob
.sync('./**/*.ftl', {
cwd: testsPath,
nodir: true,
absolute: true,
})
.map((file) => [path.basename(file), file]);

for (const file of files) {
describe(path.basename(file), () => {
const template = fs.readFileSync(file, 'utf8');
const data = parser.parse(template);
describe.each(files)('%s', (_, file) => {
const template = fs.readFileSync(file, 'utf8');
const data = parser.parse(template);

it('should have no errors', () => {
expect(data.ast.errors).toBeFalsy();
});
it('should have no errors', () => {
expect(data.ast.errors).toBeFalsy();
});

it('should have correct tokens', () => {
expect(data.tokens).toMatchSnapshot();
});
it('should have correct tokens', () => {
expect(data.tokens).toMatchSnapshot();
});

it('should have correct ast', () => {
expect(data.ast).toMatchSnapshot();
});
it('should have correct ast', () => {
expect(data.ast).toMatchSnapshot();
});
}
});
7 changes: 6 additions & 1 deletion test/tokenizer-invalid.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Tokenizer } from '../src';
import ParseError from '../src/errors/ParseError';
import { Token } from '../src/interface/Tokens';

const tokenizer = new Tokenizer();
Expand All @@ -7,7 +8,11 @@ function parse(text: string): Token[] {
try {
return tokenizer.parse(text);
} catch (e) {
throw new Error(`${e.message} [${e.start}-${e.end}]`);
if (e instanceof ParseError) {
throw new Error(`${e.message} [${e.start}-${e.end}]`);
} else {
throw e;
}
}
}

Expand Down
Loading

0 comments on commit 160c6fc

Please sign in to comment.