Skip to content

Commit

Permalink
feat(peer-deps): support @angular/compiler@8 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 1, 2020
1 parent 604d863 commit 44ecf5d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ script:
- yarn run lint
- yarn run test

- yarn upgrade @angular/compiler@8.0.0
- node -e "assert.equal(require('@angular/compiler').VERSION.full, '8.0.0')"
- yarn run test

- yarn upgrade @angular/compiler@7
- node -e "assert.equal(require('@angular/compiler').VERSION.major, '7')"
- yarn run test

- yarn upgrade @angular/compiler@6
- node -e "assert.equal(require('@angular/compiler').VERSION.major, '6')"
- yarn run test

after_script:
- codecov

Expand Down
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const NG_VERSION = require('@angular/compiler').VERSION.full;

module.exports = {
globals: {
'ts-jest': {
diagnostics: !/^(?:[67]|8\.[01])\./.test(NG_VERSION),
}
},
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'js', 'json'],
testMatch: ['**/*.test.ts'],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"tslib": "^1.9.3"
},
"devDependencies": {
"@angular/compiler": "6.0.0",
"@angular/compiler": "8.2.0",
"@babel/code-frame": "7.8.3",
"@babel/parser": "7.6.4",
"@babel/types": "7.1.5",
Expand All @@ -46,7 +46,7 @@
"typescript": "3.7.5"
},
"peerDependencies": {
"@angular/compiler": "^6.0.0 || ^7.0.0"
"@angular/compiler": "^6.0.0 || ^7.0.0 || ^8.0.0"
},
"engines": {
"node": ">= 6"
Expand Down
19 changes: 14 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import { VERSION as NG_VERSION } from '@angular/compiler';
import * as ng from '@angular/compiler/src/expression_parser/ast';
import { Lexer } from '@angular/compiler/src/expression_parser/lexer';
import { Parser } from '@angular/compiler/src/expression_parser/parser';
import { RawNGComment, RawNGSpan } from './types';

const NG_PARSE_FAKE_LOCATION = 'angular-estree-parser';
const NG_PARSE_TEMPLATE_BINDINGS_FAKE_PREFIX = 'NgEstreeParser';
const NG_PARSE_FAKE_ABSOLUTE_OFFSET = 0;
/* istanbul ignore next */
const NG_PARSE_SHARED_PARAMS: readonly [
string,
number,
] = /^(?:[67]|8\.[01])\./.test(NG_VERSION.full)
? ([NG_PARSE_FAKE_LOCATION] as any)
: ([NG_PARSE_FAKE_LOCATION, NG_PARSE_FAKE_ABSOLUTE_OFFSET] as const);

function createNgParser() {
return new Parser(new Lexer());
Expand All @@ -23,19 +32,19 @@ function parseNg(

export function parseNgBinding(input: string) {
return parseNg(input, (astInput, ngParser) =>
ngParser.parseBinding(astInput, NG_PARSE_FAKE_LOCATION),
ngParser.parseBinding(astInput, ...NG_PARSE_SHARED_PARAMS),
);
}

export function parseNgSimpleBinding(input: string) {
return parseNg(input, (astInput, ngParser) =>
ngParser.parseSimpleBinding(astInput, NG_PARSE_FAKE_LOCATION),
ngParser.parseSimpleBinding(astInput, ...NG_PARSE_SHARED_PARAMS),
);
}

export function parseNgAction(input: string) {
return parseNg(input, (astInput, ngParser) =>
ngParser.parseAction(astInput, NG_PARSE_FAKE_LOCATION),
ngParser.parseAction(astInput, ...NG_PARSE_SHARED_PARAMS),
);
}

Expand All @@ -44,7 +53,7 @@ export function parseNgTemplateBindings(input: string) {
const { templateBindings: ast, errors } = ngParser.parseTemplateBindings(
NG_PARSE_TEMPLATE_BINDINGS_FAKE_PREFIX,
input,
NG_PARSE_FAKE_LOCATION,
...NG_PARSE_SHARED_PARAMS,
);
assertAstErrors(errors);
return ast;
Expand All @@ -57,7 +66,7 @@ export function parseNgInterpolation(input: string) {
const suffix = '}}';
const { ast: rawAst, errors } = ngParser.parseInterpolation(
prefix + astInput + suffix,
NG_PARSE_FAKE_LOCATION,
...NG_PARSE_SHARED_PARAMS,
)!;
assertAstErrors(errors);
const ast = (rawAst as ng.Interpolation).expressions[0];
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@angular/compiler@6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-6.0.0.tgz#9092a0f02f33dd1108276ab93cc48142e36a1e95"
integrity sha512-UsYfsvHf4VVtkhzM7tyabh8co7gqWZTm3p79hbLDeyCEojl0AkrwbSgh0DQnKRxp4Tu3DEeeDkg1ahA7n19I8A==
"@angular/compiler@8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@angular/compiler/-/compiler-8.2.0.tgz#216cbebb9e9a59c2037746112dbf044a26670e36"
integrity sha512-5OlLfL6cie8XAY+pPc+iCouzO07V5Lahmyr6OVKMjePJO5SkPuVdm/OPdR43n3VNlOje4bwHHvoTok1BKepDTg==
dependencies:
tslib "^1.9.0"

Expand Down

0 comments on commit 44ecf5d

Please sign in to comment.