Comments (5)
OK, I'll take a look.
from angular.
This appears to have been broken by angular/vscode-ng-language-service@bd6282e. @ivanwonder If you have and time, would you be able to take a look at this? I clearly don't understand the tokenizer and can't look into it more anytime soon.
from angular.
@ivanwonder Thank you! We don't necessarily need the whole implementation that TypeScript has for this because we don't care about tokenizing all the parts correctly. All we really need to know is where the start and end is of the string. But maybe the easiest way to do that is just tokenizing the whole thing correctly by copying the TS code.
from angular.
Yes, the tokenizer is complex, and I also can't fully understand it, and make sure this will work for us.
- const a =`abc`
The token is ts.SyntaxKind.NoSubstitutionTemplateLiteral
which includes the CloseBraceToken
. We don't need to call the reScanTemplateToken
.
- const a = `ab${1}c`
We need to call the reScanTemplateToken
when encountering a CloseBraceToken
.
- const a = `ab${b({})}c`
This includes an object {}
, we need to record the OpenBraceToken
, close them all, then call the reScanTemplateToken
.
But maybe the easiest way to do that is just tokenizing the whole thing correctly by copying the TS code.
I think this is what the ts.createSourceFile
does. Scan the code and create the AST tree.
https://github.com/microsoft/TypeScript/blob/806d7340472082e5ff6d844ecdb70a4b5165e8c5/src/compiler/parser.ts#L1592
I have an idea about the original problem, I guess which is the diagnostics can be quite expensive. In the typescript the type checker can be interrupted.
// Cancellation that controls whether or not we can cancel in the middle of type checking.
// In general cancelling is *not* safe for the type checker. We might be in the middle of
// computing something, and we will leave our internals in an inconsistent state. Callers
// who set the cancellation token should catch if a cancellation exception occurs, and
// should throw away and create a new TypeChecker.
//
// Currently we only support setting the cancellation token when getting diagnostics. This
// is because diagnostics can be quite expensive, and we want to allow hosts to bail out if
// they no longer need the information (for example, if the user started editing again).
var cancellationToken: CancellationToken | undefined;
function runWithCancellationToken<T>(func: () => T): T {
try {
return func();
}
catch (e) {
if (e instanceof OperationCanceledException) {
// We were canceled while performing the operation. Because our type checker
// might be a bad state, we need to throw it away.
typeChecker = undefined!;
}
throw e;
}
}
This copy is from here. https://github.com/microsoft/TypeScript/blob/806d7340472082e5ff6d844ecdb70a4b5165e8c5/src/compiler/checker.ts#L1435
https://github.com/microsoft/TypeScript/blob/806d7340472082e5ff6d844ecdb70a4b5165e8c5/src/compiler/program.ts#L2853
Maybe we can evaluate this option, and try to throw an error in the template type checker and catch the error in the NgCompiler
when the request is canceled.
from angular.
I think this is what the ts.createSourceFile does. Scan the code and create the AST tree.
Yea, this is probably the direction we should go at this point (creating a temporary source file). We can copy the same code used on the server side here:
angular/packages/language-service/src/language_service.ts
Lines 604 to 621 in 75a186e
from angular.
Related Issues (20)
- Angular compiler seemingly false negative warning : optional chaining refused on array item HOT 3
- ActivatedRoute in Directive: Snapshot.params are not getting updated HOT 2
- APP_INITIALIZER with HttpClient provoke memory leak in SSR projects HOT 8
- New Angular Docs website is not PWA compatible
- @for can't be used for forms where $index based calls on removeAt() are necessary HOT 1
- Recording already in progress issue in Profiler
- SSR won't render [style.background-image] with base64 URL values
- Btter Docs About Error handling in httpClient HOT 2
- No compile time error/warning in HTML template when Signals variable used without parenthesis HOT 2
- Fail to load docs HOT 1
- We couldn't start the tutorial app. HOT 2
- ngProjectedAs not working when used as static host property inside @Component
- "Could not resolve dependency" for ts version in webcontainers at adev HOT 1
- ESBuild not calling any http request in server side HOT 2
- Unable to hydrate nested anchor elements HOT 3
- Broken links on ng-template reference page HOT 1
- [tour-of-heroes/toh-pt1][Format with the UppercasePipe] adding pipe {{hero.name | uppercase }} requires "CommonModule" HOT 1
- fetch resulting in respons.json already parsed error HOT 2
- Broken link `/tutorials/learn-angular/inject-based-di`
- Pipes Api not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular.