Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 1013653004: Suppress generation of JsGlobal and JsType code and use window as the default value instead of {} f… (Closed) Base URL: git@github.com:dart-lang/dart-dev-compiler.git@master
Patch Set: ptal Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | test/codegen/dom.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 6f135f0d21cad9d566835518470bb9e35b167124..e9f0a5d0e1bff103415d6dd826f907cf2bed5fad 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -34,6 +34,15 @@ import 'code_generator.dart';
// This must match the optional parameter name used in runtime.js
const String _jsNamedParameterName = r'opt$';
+bool _isAnnotationType(Annotation m, String name) => m.name.name == name;
+
+Annotation _getAnnotation(AnnotatedNode node, String name) => node.metadata
+ .firstWhere((annotation) => _isAnnotationType(annotation, name),
+ orElse: () => null);
+
+Annotation _getJsNameAnnotation(AnnotatedNode node) =>
+ _getAnnotation(node, "JsName");
+
class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
final LibraryInfo libraryInfo;
final TypeRules rules;
@@ -60,6 +69,19 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
JS.Program generateLibrary(
Iterable<CompilationUnit> units, CheckerReporter reporter) {
+ var unit = units.first;
+ var jsDefaultValue = '{}';
+ if (unit.directives.isNotEmpty) {
+ var annotation = _getJsNameAnnotation(unit.directives.first);
+ if (annotation != null) {
+ var arguments = annotation.arguments.arguments;
+ if (!arguments.isEmpty) {
+ var namedExpression = arguments.first as NamedExpression;
+ var literal = namedExpression.expression as SimpleStringLiteral;
+ jsDefaultValue = literal.stringValue;
+ }
+ }
+ }
var body = <JS.Statement>[];
for (var unit in units) {
// TODO(jmesserly): this is needed because RestrictedTypeRules can send
@@ -80,10 +102,12 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
}
var name = jsLibraryName(libraryInfo.library);
+
+ var defaultValue = js.call(jsDefaultValue);
return new JS.Program([
js.statement('var #;', name),
- js.statement("(function($_EXPORTS) { 'use strict'; #; })(# || (# = {}));",
- [body, name, name])
+ js.statement("(function($_EXPORTS) { 'use strict'; #; })(# || (# = #));",
+ [body, name, name, defaultValue])
]);
}
@@ -231,6 +255,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
@override
JS.Statement visitClassDeclaration(ClassDeclaration node) {
+ if (_getJsNameAnnotation(node) != null) return null;
+
currentClass = node;
var body = <JS.Statement>[];
« no previous file with comments | « lib/src/codegen/html_codegen.dart ('k') | test/codegen/dom.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698