| 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>[];
|
|
|