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
Ivy hello world with devserver #22788
Changes from all commits
5bcf297
cbcc6b8
a049f4d
5b1371f
9d1a8ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!doctype html> | ||
|
||
<html> | ||
<head> | ||
<title>Angular Hello World Example</title> | ||
</head> | ||
<body> | ||
<!-- The Angular application will be bootstrapped into this element. --> | ||
<hello-world></hello-world> | ||
|
||
<!-- | ||
Script tag which bootstraps the application. Use `?debug` in URL to select | ||
the debug version of the script. | ||
|
||
There are two scripts sources: `bundle.min.js` and `bundle.min_debug.js` You can | ||
switch between which bundle the browser loads to experiment with the application. | ||
|
||
- `bundle.min.js`: Is what the site would serve to their users. It has gone | ||
through rollup, build-optimizer, and uglify with tree shaking. | ||
- `bundle.min_debug.js`: Is what the developer would like to see when debugging | ||
the application. It has also done through full pipeline of rollup, build-optimizer, | ||
and uglify, however special flags were passed to uglify to prevent inlining and | ||
property renaming. | ||
--> | ||
<script> | ||
document.write('<script src="' + | ||
(document.location.search.endsWith('debug') ? '/bundle.min_debug.js' : '/bundle.min.js') + | ||
'"></' + 'script>'); | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,15 +22,17 @@ export class SymbolExtractor { | |
static parse(path: string, contents: string): Symbol[] { | ||
const symbols: Symbol[] = []; | ||
const source: ts.SourceFile = ts.createSourceFile(path, contents, ts.ScriptTarget.Latest, true); | ||
let fnDepth = 0; | ||
let fnRecurseDepth = 0; | ||
function visitor(child: ts.Node) { | ||
// Left for easier debugging. | ||
// console.log('>>>', ts.SyntaxKind[child.kind]); | ||
switch (child.kind) { | ||
case ts.SyntaxKind.FunctionExpression: | ||
fnDepth++; | ||
if (fnDepth <= 1) { | ||
// Only go into function expression once for the outer closure. | ||
fnRecurseDepth++; | ||
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. don't you ever need to 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. good catch, added. 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. do we need the test to be updated ? 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. For this to fail, we would have to have more than one top level closure, which does not happen in real life. Not sure that would be useful, what do you think. 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. I would update the test but it's up to you. |
||
if (fnRecurseDepth <= 1) { | ||
ts.forEachChild(child, visitor); | ||
} | ||
fnRecurseDepth--; | ||
break; | ||
case ts.SyntaxKind.SourceFile: | ||
case ts.SyntaxKind.VariableStatement: | ||
|
@@ -44,9 +46,13 @@ export class SymbolExtractor { | |
break; | ||
case ts.SyntaxKind.VariableDeclaration: | ||
const varDecl = child as ts.VariableDeclaration; | ||
if (varDecl.initializer) { | ||
if (varDecl.initializer && fnRecurseDepth !== 0) { | ||
symbols.push({name: varDecl.name.getText()}); | ||
} | ||
if (fnRecurseDepth == 0 && | ||
isRollupExportSymbol(child.parent as ts.VariableDeclarationList)) { | ||
ts.forEachChild(child, visitor); | ||
} | ||
break; | ||
case ts.SyntaxKind.FunctionDeclaration: | ||
const funcDecl = child as ts.FunctionDeclaration; | ||
|
@@ -114,3 +120,15 @@ function toSymbol(v: string | Symbol): Symbol { | |
function toName(symbol: Symbol): string { | ||
return symbol.name; | ||
} | ||
|
||
/** | ||
* Detects if VariableDeclarationList is format `var x = function(){}()`; | ||
* | ||
* Rollup produces this format when it wants to export symbols from a bundle. | ||
* @param child | ||
*/ | ||
function isRollupExportSymbol(child: ts.VariableDeclarationList): boolean { | ||
if (child.declarations.length !== 1) return false; | ||
const decl: ts.VariableDeclaration = child.declarations[0]; | ||
return !!(decl.initializer && decl.initializer.kind == ts.SyntaxKind.CallExpression); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* Rollup exports symbols in this particular way. This test demonstrates that we can correctly read | ||
* symbols. | ||
*/ | ||
var fooBar = function(exports) { | ||
'use strict'; | ||
// tslint:disable-next-line:no-console | ||
console.log('Hello, Alice in Wonderland'); | ||
var A = function() { | ||
function A() {} | ||
A.prototype.a = function() { return document.a; }; | ||
return A; | ||
}(); | ||
// tslint:disable-next-line:no-console | ||
console.error(new A().a()); | ||
exports.A = A; | ||
return exports; | ||
}({}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
"A" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a
TODO...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don' think so. These are all over the code base, and there will have to be big clean up once that is resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should
ComponentType
be an union type with a TODO then ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because then it would apply to all cases and we would lose type safety internally. We really just want it on the user code Ivy boundary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like a
FromUserComponentType
?