-
Notifications
You must be signed in to change notification settings - Fork 26.2k
feat(compiler): add support for the typeof
keyword in template expressions
#58183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d2f3f00
feat(compiler): add support for the `typeof` keyword in template expr…
JeanMeche 992769f
fixup! feat(compiler): add support for the `typeof` keyword in templa…
JeanMeche 1780abd
fixup! feat(compiler): add support for the `typeof` keyword in templa…
JeanMeche 65e0fb9
fixup! feat(compiler): add support for the `typeof` keyword in templa…
JeanMeche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
packages/compiler-cli/test/compliance/test_cases/r3_view_compiler/operators.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import {Component, NgModule} from '@angular/core'; | ||
import {Component, NgModule, Pipe} from '@angular/core'; | ||
|
||
@Component({ | ||
template: ` | ||
{{ 1 + 2 }} | ||
{{ (1 % 2) + 3 / 4 * 5 }} | ||
{{ +1 }} | ||
{{ typeof {} === 'object' }} | ||
{{ !(typeof {} === 'object') }} | ||
{{ typeof foo?.bar === 'string' }} | ||
{{ typeof foo?.bar | identity }} | ||
`, | ||
standalone: false | ||
}) | ||
export class MyApp { | ||
foo: {bar?: string} = {bar: 'baz'}; | ||
} | ||
|
||
@NgModule({declarations: [MyApp]}) | ||
@Pipe ({name: 'identity'}) | ||
export class IdentityPipe { | ||
transform(value: any) { return value; } | ||
} | ||
|
||
@NgModule({declarations: [MyApp, IdentityPipe]}) | ||
export class MyModule { | ||
} |
11 changes: 10 additions & 1 deletion
11
packages/compiler-cli/test/compliance/test_cases/r3_view_compiler/operators_template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
template: function MyApp_Template(rf, $ctx$) { | ||
if (rf & 1) { | ||
$i0$.ɵɵtext(0); | ||
i0.ɵɵpipe(1, "identity"); | ||
} if (rf & 2) { | ||
i0.ɵɵtextInterpolate3(" ", 1 + 2, " ", 1 % 2 + 3 / 4 * 5, " ", +1, "\n"); | ||
i0.ɵɵtextInterpolate7(" ", | ||
1 + 2, " ", | ||
1 % 2 + 3 / 4 * 5, " ", | ||
+1, " ", | ||
typeof i0.ɵɵpureFunction0(9, _c0) === "object", " ", | ||
!(typeof i0.ɵɵpureFunction0(10, _c0) === "object"), " ", | ||
typeof (ctx.foo == null ? null : ctx.foo.bar) === "string", " ", | ||
i0.ɵɵpipeBind1(1, 7, typeof (ctx.foo == null ? null : ctx.foo.bar)), "\n" | ||
); | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,19 @@ export enum TokenType { | |
Error, | ||
} | ||
|
||
const KEYWORDS = ['var', 'let', 'as', 'null', 'undefined', 'true', 'false', 'if', 'else', 'this']; | ||
const KEYWORDS = [ | ||
'var', | ||
'let', | ||
'as', | ||
'null', | ||
'undefined', | ||
'true', | ||
'false', | ||
'if', | ||
'else', | ||
'this', | ||
'typeof', | ||
]; | ||
|
||
export class Lexer { | ||
tokenize(text: string): Token[] { | ||
|
@@ -99,6 +111,10 @@ export class Token { | |
return this.type == TokenType.Keyword && this.strValue == 'this'; | ||
} | ||
|
||
isKeywordTypeof(): boolean { | ||
return this.type === TokenType.Keyword && this.strValue === 'typeof'; | ||
} | ||
|
||
isError(): boolean { | ||
return this.type == TokenType.Error; | ||
} | ||
|
@@ -436,18 +452,6 @@ function isIdentifierStart(code: number): boolean { | |
); | ||
} | ||
|
||
export function isIdentifier(input: string): boolean { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was unused. |
||
if (input.length == 0) return false; | ||
const scanner = new _Scanner(input); | ||
if (!isIdentifierStart(scanner.peek)) return false; | ||
scanner.advance(); | ||
while (scanner.peek !== chars.$EOF) { | ||
if (!isIdentifierPart(scanner.peek)) return false; | ||
scanner.advance(); | ||
} | ||
return true; | ||
} | ||
|
||
function isIdentifierPart(code: number): boolean { | ||
return chars.isAsciiLetter(code) || chars.isDigit(code) || code == chars.$_ || code == chars.$$; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.