| Index: lib/src/emitters.dart
|
| diff --git a/lib/src/emitters.dart b/lib/src/emitters.dart
|
| index 31447f82677f586854afb04b6e1fd35618cdc8a6..8edc355cabf09ce7f942f6b03e4fd5b011194542 100644
|
| --- a/lib/src/emitters.dart
|
| +++ b/lib/src/emitters.dart
|
| @@ -15,6 +15,7 @@ import 'package:source_maps/span.dart' show Span, FixedLocation;
|
|
|
| import 'code_printer.dart';
|
| import 'codegen.dart' as codegen;
|
| +import 'dart_parser.dart' show DartCodeInfo;
|
| import 'html5_utils.dart';
|
| import 'html5_setters.g.dart';
|
| import 'info.dart';
|
| @@ -435,11 +436,11 @@ class WebComponentEmitter extends RecursiveEmitter {
|
| var superclass = hasExtends ? info.extendsComponent.constructor
|
| : 'autogenerated.WebComponent';
|
| codeInfo = new DartCodeInfo(null, null, [],
|
| - 'class ${info.constructor} extends $superclass {\n}');
|
| + 'class ${info.constructor} extends $superclass {\n}', null);
|
| }
|
|
|
| var code = codeInfo.code;
|
| - var match = new RegExp('class ${info.constructor}[^{]*{').firstMatch(code);
|
| + var match = codeInfo.findClass(info.constructor);
|
| if (match != null) {
|
| var printer = new CodePrinter(0);
|
| var libraryName = (codeInfo.libraryName != null)
|
| @@ -448,9 +449,10 @@ class WebComponentEmitter extends RecursiveEmitter {
|
| var declaringPath = info.declaringFile.path;
|
| printer.addLine(codegen.header(declaringPath, libraryName));
|
|
|
| - // Add exisitng import, export, and part directives.
|
| + // Add existing import, export, and part directives.
|
| for (var directive in codeInfo.directives) {
|
| - printer.addLine(codegen.directiveText(directive, info, pathInfo));
|
| + // TODO(jmesserly): add span here
|
| + printer.addLine(directive.toString());
|
| }
|
|
|
| // Add imports only for those components used by this component.
|
| @@ -469,7 +471,8 @@ class WebComponentEmitter extends RecursiveEmitter {
|
| ..add(codegen.importList(imports),
|
| location: new FixedLocation(0, declaringPath.toString(), 0, 0))
|
| ..addLine('')
|
| - ..add(code.substring(0, match.end))
|
| + // TODO(jmesserly): add span here
|
| + ..add(code.substring(codeInfo.directivesEnd, match.leftBracket.end))
|
| ..add('\n')
|
| ..indent += 1
|
| ..addLine('/** Autogenerated from the template. */')
|
| @@ -515,7 +518,9 @@ class WebComponentEmitter extends RecursiveEmitter {
|
| ..addLine('')
|
| ..addLine('/** Original code from the component. */')
|
| ..indent -= 1
|
| - ..add(code.substring(match.end));
|
| + // TODO(jmesserly): add span here
|
| + ..add(code.substring(match.leftBracket.end));
|
| +
|
| } else {
|
| messages.error('please provide a class definition '
|
| 'for ${info.constructor}:\n $code', info.element.sourceSpan,
|
| @@ -534,25 +539,25 @@ class MainPageEmitter extends RecursiveEmitter {
|
|
|
| // fix up the URLs to content that is not modified by the compiler
|
| document.queryAll('script').forEach((tag) {
|
| - var src = tag.attributes["src"];
|
| - if (tag.attributes['type'] == 'application/dart') {
|
| - tag.remove();
|
| - } else if (src != null) {
|
| - tag.attributes["src"] = pathInfo.transformUrl(_fileInfo.path, src);
|
| - }
|
| + var src = tag.attributes["src"];
|
| + if (tag.attributes['type'] == 'application/dart') {
|
| + tag.remove();
|
| + } else if (src != null) {
|
| + tag.attributes["src"] = pathInfo.transformUrl(_fileInfo.path, src);
|
| + }
|
| });
|
| document.queryAll('link').forEach((tag) {
|
| - var href = tag.attributes['href'];
|
| - if (tag.attributes['rel'] == 'components') {
|
| - tag.remove();
|
| - } else if (href != null) {
|
| - tag.attributes['href'] = pathInfo.transformUrl(_fileInfo.path, href);
|
| - }
|
| - });
|
| + var href = tag.attributes['href'];
|
| + if (tag.attributes['rel'] == 'components') {
|
| + tag.remove();
|
| + } else if (href != null) {
|
| + tag.attributes['href'] = pathInfo.transformUrl(_fileInfo.path, href);
|
| + }
|
| + });
|
|
|
| var printer = new CodePrinter(0);
|
|
|
| - // Inject library name if not pressent.
|
| + // Inject library name if not present.
|
| var codeInfo = _fileInfo.userCode;
|
| if (codeInfo == null) {
|
| codeInfo = new DartCodeInfo(null, null, [], 'main(){\n}');
|
| @@ -561,32 +566,51 @@ class MainPageEmitter extends RecursiveEmitter {
|
| ? codeInfo.libraryName : _fileInfo.libraryName;
|
| printer.add(codegen.header(_fileInfo.path, libraryName));
|
|
|
| - // Add exisitng import, export, and part directives.
|
| + // Add existing import, export, and part directives.
|
| for (var directive in codeInfo.directives) {
|
| - printer.addLine(codegen.directiveText(directive, _fileInfo, pathInfo));
|
| + // TODO(jmesserly): add span here
|
| + printer.addLine(directive.toString());
|
| }
|
|
|
| // Import only those components used by the page.
|
| var imports = _fileInfo.usedComponents.keys.map(
|
| (c) => pathInfo.relativePath(_fileInfo, c));
|
| return printer..add(codegen.importList(imports))
|
| - ..addLine('')
|
| - ..addLine('')
|
| - ..addLine('// Original code')
|
| - ..add(codeInfo.code)
|
| - ..addLine('')
|
| - ..addLine('// Additional generated code')
|
| - ..addLine('void init_autogenerated() {')
|
| - ..indent += 1
|
| - ..addLine('var _root = autogenerated.document.body;')
|
| - ..add(_context.declarations)
|
| - ..addLine('var __t = new autogenerated.Template(_root);')
|
| - ..add(_context.printer)
|
| - ..addLine('__t.create();')
|
| - ..addLine('__t..insert();')
|
| - ..indent -= 1
|
| - ..addLine('}');
|
| + ..addLine('')
|
| + ..addLine('')
|
| + ..addLine('// Original code')
|
| + // TODO(jmesserly): add span here
|
| + ..add(codeInfo.codeAfterDirectives())
|
| + ..addLine('')
|
| + ..addLine('// Additional generated code')
|
| + ..addLine('void init_autogenerated() {')
|
| + ..indent += 1
|
| + ..addLine('var _root = autogenerated.document.body;')
|
| + ..add(_context.declarations)
|
| + ..addLine('var __t = new autogenerated.Template(_root);')
|
| + ..add(_context.printer)
|
| + ..addLine('__t.create();')
|
| + ..addLine('__t..insert();')
|
| + ..indent -= 1
|
| + ..addLine('}');
|
| + }
|
| +}
|
| +
|
| +/** Emits a .dart file using the [DartCodeInfo]. */
|
| +CodePrinter emitDartFile(FileInfo fileInfo, PathInfo pathInfo) {
|
| + var printer = new CodePrinter(0);
|
| +
|
| + // Inject library name if not present.
|
| + var codeInfo = fileInfo.userCode;
|
| + printer.add(codegen.header(fileInfo.path, codeInfo.libraryName));
|
| +
|
| + // Add existing import, export, and part directives.
|
| + // TODO(jmesserly): add spans here
|
| + for (var directive in codeInfo.directives) {
|
| + printer.addLine(directive.toString());
|
| }
|
| + printer.add(codeInfo.codeAfterDirectives());
|
| + return printer;
|
| }
|
|
|
| /** Clears all fields in [declarations]. */
|
|
|