| Index: pkg/polymer/test/build/all_phases_test.dart
|
| diff --git a/pkg/polymer/test/build/all_phases_test.dart b/pkg/polymer/test/build/all_phases_test.dart
|
| index 58a80f7b65d2813479d78f816d443d1ee4653dd8..2427976eeec7b2bde6d2c68c2a9f888cc1fd78ee 100644
|
| --- a/pkg/polymer/test/build/all_phases_test.dart
|
| +++ b/pkg/polymer/test/build/all_phases_test.dart
|
| @@ -6,6 +6,8 @@ library polymer.test.build.all_phases_test;
|
|
|
| import 'package:code_transformers/tests.dart' show testingDartSdkDirectory;
|
| import 'package:polymer/src/build/common.dart';
|
| +import 'package:polymer/src/build/import_inliner.dart' show COMPONENT_WARNING;
|
| +import 'package:polymer/src/build/linter.dart' show USE_POLYMER_HTML;
|
| import 'package:polymer/src/build/script_compactor.dart' show MAIN_HEADER;
|
| import 'package:polymer/transformer.dart';
|
| import 'package:smoke/codegen/generator.dart' show DEFAULT_IMPORTS;
|
| @@ -21,60 +23,66 @@ void main() {
|
| testPhases('no changes', phases, {
|
| 'a|web/test.html': '<!DOCTYPE html><html></html>',
|
| }, {}, [
|
| - 'error: To run a polymer application, you need to call "initPolymer". You'
|
| - ' can either include a generic script tag that does this for you:\'<'
|
| - 'script type="application/dart">export "package:polymer/init.dart";'
|
| - '</script>\' or add your own script tag and call that function. Make sure'
|
| - ' the script tag is placed after all HTML imports.'
|
| + 'warning: $USE_POLYMER_HTML'
|
| ]);
|
|
|
| testPhases('observable changes', phases, {
|
| - 'a|web/test.dart': _sampleObservable('A', 'foo'),
|
| - 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'),
|
| + 'a|web/test.dart': _sampleInput('A', 'foo'),
|
| + 'a|web/test2.dart': _sampleOutput('B', 'bar'),
|
| }, {
|
| - 'a|web/test.dart': _sampleObservableOutput('A', 'foo'),
|
| - 'a|web/test2.dart': _sampleObservableOutput('B', 'bar'),
|
| + 'a|web/test.dart': _sampleOutput('A', 'foo'),
|
| + 'a|web/test2.dart': _sampleOutput('B', 'bar'),
|
| });
|
|
|
| testPhases('single script', phases, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| - '<script type="application/dart" src="a.dart"></script>',
|
| - 'a|web/a.dart': _sampleObservable('A', 'foo'),
|
| + '<link rel="import" href="packages/polymer/polymer.html">'
|
| + '<script type="application/dart;component=1" src="a.dart"></script>',
|
| + 'a|web/a.dart': _sampleInput('A', 'foo'),
|
| }, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| '$WEB_COMPONENTS_TAG'
|
| - '$INTEROP_TAG'
|
| + '</head><body>'
|
| '<script src="test.html_bootstrap.dart.js"></script>'
|
| - '</head><body></body></html>',
|
| + '</body></html>',
|
|
|
| 'a|web/test.html_bootstrap.dart':
|
| '''$MAIN_HEADER
|
| import 'a.dart' as i0;
|
| ${DEFAULT_IMPORTS.join('\n')}
|
| + import 'a.dart' as smoke_0;
|
| + import 'package:polymer/polymer.dart' as smoke_1;
|
|
|
| void main() {
|
| useGeneratedCode(new StaticConfiguration(
|
| - checkedMode: false));
|
| - configureForDeployment([
|
| + checkedMode: false,
|
| + parents: {
|
| + smoke_0.XA: smoke_1.PolymerElement,
|
| + },
|
| + declarations: {
|
| + smoke_0.XA: const {},
|
| + }));
|
| + startPolymer([
|
| + i0.m_foo,
|
| + () => Polymer.register('x-A', i0.XA),
|
| ]);
|
| - i0.main();
|
| }
|
| '''.replaceAll('\n ', '\n'),
|
| - 'a|web/a.dart': _sampleObservableOutput('A', 'foo'),
|
| + 'a|web/a.dart': _sampleOutput('A', 'foo'),
|
| });
|
|
|
| testPhases('single inline script', phases, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| - '<script type="application/dart">'
|
| - '${_sampleObservable("B", "bar")}</script>',
|
| + '<link rel="import" href="packages/polymer/polymer.html">'
|
| + '<script type="application/dart;component=1">'
|
| + '${_sampleInput("B", "bar")}</script>',
|
| }, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| '$WEB_COMPONENTS_TAG'
|
| - '$INTEROP_TAG'
|
| '</head><body>'
|
| '<script src="test.html_bootstrap.dart.js"></script>'
|
| '</body></html>',
|
| @@ -83,94 +91,160 @@ void main() {
|
| '''$MAIN_HEADER
|
| import 'test.html.0.dart' as i0;
|
| ${DEFAULT_IMPORTS.join('\n')}
|
| + import 'test.html.0.dart' as smoke_0;
|
| + import 'package:polymer/polymer.dart' as smoke_1;
|
|
|
| void main() {
|
| useGeneratedCode(new StaticConfiguration(
|
| - checkedMode: false));
|
| - configureForDeployment([
|
| + checkedMode: false,
|
| + parents: {
|
| + smoke_0.XB: smoke_1.PolymerElement,
|
| + },
|
| + declarations: {
|
| + smoke_0.XB: const {},
|
| + }));
|
| + startPolymer([
|
| + i0.m_bar,
|
| + () => Polymer.register('x-B', i0.XB),
|
| ]);
|
| - i0.main();
|
| }
|
| '''.replaceAll('\n ', '\n'),
|
| 'a|web/test.html.0.dart':
|
| - _sampleObservableOutput("B", "bar"),
|
| + _sampleOutput("B", "bar"),
|
| });
|
|
|
| - const onlyOne = 'warning: Only one "application/dart" script tag per document'
|
| - ' is allowed.';
|
| - const moreNotSupported =
|
| - 'warning: more than one Dart script per HTML document is not supported. '
|
| - 'Script will be ignored.';
|
| -
|
| - testPhases('several scripts', phases, {
|
| + testPhases('several application scripts', phases, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| - '<script type="application/dart" src="a.dart"></script>'
|
| - // TODO(sigmund): provide a way to see logging warnings and errors.
|
| - // For example, these extra tags produce warnings and are then removed
|
| - // by the transformers. The test below checks that the output looks
|
| - // correct, but we should also validate the messages logged.
|
| + '<link rel="import" href="packages/polymer/polymer.html">'
|
| + '<script type="application/dart;component=1" src="a.dart"></script>'
|
| '<script type="application/dart">'
|
| - '${_sampleObservable("B", "bar")}</script>'
|
| + '${_sampleInput("B", "bar")}</script>'
|
| '</head><body><div>'
|
| '<script type="application/dart">'
|
| - '${_sampleObservable("C", "car")}</script>'
|
| + '${_sampleInput("C", "car")}</script>'
|
| '</div>'
|
| '<script type="application/dart" src="d.dart"></script>',
|
| - 'a|web/a.dart': _sampleObservable('A', 'foo'),
|
| + 'a|web/a.dart': _sampleInput('A', 'foo'),
|
| }, {
|
| 'a|web/test.html':
|
| '<!DOCTYPE html><html><head>'
|
| '$WEB_COMPONENTS_TAG'
|
| - '$INTEROP_TAG'
|
| '</head><body>'
|
| + '<script src="test.html.0.dart.js"></script>'
|
| + '<div>'
|
| + '<script src="test.html.1.dart.js"></script>'
|
| + '</div>'
|
| + '<script src="d.dart.js"></script>'
|
| '<script src="test.html_bootstrap.dart.js"></script>'
|
| - '<div></div>'
|
| '</body></html>',
|
|
|
| 'a|web/test.html_bootstrap.dart':
|
| '''$MAIN_HEADER
|
| import 'a.dart' as i0;
|
| ${DEFAULT_IMPORTS.join('\n')}
|
| + import 'a.dart' as smoke_0;
|
| + import 'package:polymer/polymer.dart' as smoke_1;
|
|
|
| void main() {
|
| useGeneratedCode(new StaticConfiguration(
|
| - checkedMode: false));
|
| - configureForDeployment([
|
| + checkedMode: false,
|
| + parents: {
|
| + smoke_0.XA: smoke_1.PolymerElement,
|
| + },
|
| + declarations: {
|
| + smoke_0.XA: const {},
|
| + }));
|
| + startPolymer([
|
| + i0.m_foo,
|
| + () => Polymer.register('x-A', i0.XA),
|
| ]);
|
| - i0.main();
|
| }
|
| '''.replaceAll('\n ', '\n'),
|
| - 'a|web/a.dart': _sampleObservableOutput('A', 'foo'),
|
| + 'a|web/a.dart': _sampleOutput('A', 'foo'),
|
| }, [
|
| // These should not be emitted multiple times. See:
|
| // https://code.google.com/p/dart/issues/detail?id=17197
|
| - '$onlyOne (web/test.html 0 81)',
|
| - '$onlyOne (web/test.html 8 27)',
|
| - '$onlyOne (web/test.html 16 15)',
|
| - '$moreNotSupported (web/test.html 0 81)',
|
| - '$moreNotSupported (web/test.html 8 27)',
|
| - '$moreNotSupported (web/test.html 16 15)'
|
| + 'warning: $COMPONENT_WARNING (web/test.html 14 27)',
|
| + 'warning: $COMPONENT_WARNING (web/test.html 28 15)'
|
| ]);
|
|
|
| + testPhases('several component scripts', phases, {
|
| + 'a|web/test.html':
|
| + '<!DOCTYPE html><html><head>'
|
| + '<link rel="import" href="packages/polymer/polymer.html">'
|
| + '<script type="application/dart;component=1" src="a.dart"></script>'
|
| + '<script type="application/dart;component=1">'
|
| + '${_sampleInput("B", "bar")}</script>'
|
| + '</head><body><div>'
|
| + '<script type="application/dart;component=1">'
|
| + '${_sampleInput("C", "car")}</script>'
|
| + '</div>',
|
| + 'a|web/a.dart': _sampleInput('A', 'foo'),
|
| + }, {
|
| + 'a|web/test.html':
|
| + '<!DOCTYPE html><html><head>'
|
| + '$WEB_COMPONENTS_TAG'
|
| + '</head><body>'
|
| + '<div></div>'
|
| + '<script src="test.html_bootstrap.dart.js"></script>'
|
| + '</body></html>',
|
| +
|
| + 'a|web/test.html_bootstrap.dart':
|
| + '''$MAIN_HEADER
|
| + import 'a.dart' as i0;
|
| + import 'test.html.0.dart' as i1;
|
| + import 'test.html.1.dart' as i2;
|
| + ${DEFAULT_IMPORTS.join('\n')}
|
| + import 'a.dart' as smoke_0;
|
| + import 'package:polymer/polymer.dart' as smoke_1;
|
| + import 'test.html.0.dart' as smoke_2;
|
| + import 'test.html.1.dart' as smoke_3;
|
| +
|
| + void main() {
|
| + useGeneratedCode(new StaticConfiguration(
|
| + checkedMode: false,
|
| + parents: {
|
| + smoke_0.XA: smoke_1.PolymerElement,
|
| + smoke_2.XB: smoke_1.PolymerElement,
|
| + smoke_3.XC: smoke_1.PolymerElement,
|
| + },
|
| + declarations: {
|
| + smoke_0.XA: const {},
|
| + smoke_2.XB: const {},
|
| + smoke_3.XC: const {},
|
| + }));
|
| + startPolymer([
|
| + i0.m_foo,
|
| + () => Polymer.register('x-A', i0.XA),
|
| + i1.m_bar,
|
| + () => Polymer.register('x-B', i1.XB),
|
| + i2.m_car,
|
| + () => Polymer.register('x-C', i2.XC),
|
| + ]);
|
| + }
|
| + '''.replaceAll('\n ', '\n'),
|
| + 'a|web/a.dart': _sampleOutput('A', 'foo'),
|
| + }, []);
|
| +
|
| testPhases('with imports', phases, {
|
| 'a|web/index.html':
|
| '<!DOCTYPE html><html><head>'
|
| + '<link rel="import" href="packages/polymer/polymer.html">'
|
| '<link rel="import" href="test2.html">'
|
| '</head><body>'
|
| - '<script type="application/dart" src="b.dart"></script>',
|
| - 'a|web/b.dart': _sampleObservable('B', 'bar'),
|
| + '<script type="application/dart;component=1" src="b.dart"></script>',
|
| + 'a|web/b.dart': _sampleInput('B', 'bar'),
|
| 'a|web/test2.html':
|
| '<!DOCTYPE html><html><head></head><body>'
|
| '<polymer-element name="x-a">1'
|
| - '<script type="application/dart">'
|
| - '${_sampleObservable("A", "foo")}</script>'
|
| + '<script type="application/dart;component=1">'
|
| + '${_sampleInput("A", "foo")}</script>'
|
| '</polymer-element></html>',
|
| }, {
|
| 'a|web/index.html':
|
| '<!DOCTYPE html><html><head>'
|
| '$WEB_COMPONENTS_TAG'
|
| - '$INTEROP_TAG'
|
| '</head><body><polymer-element name="x-a">1</polymer-element>'
|
| '<script src="index.html_bootstrap.dart.js"></script>'
|
| '</body></html>',
|
| @@ -179,41 +253,73 @@ void main() {
|
| import 'index.html.0.dart' as i0;
|
| import 'b.dart' as i1;
|
| ${DEFAULT_IMPORTS.join('\n')}
|
| + import 'index.html.0.dart' as smoke_0;
|
| + import 'package:polymer/polymer.dart' as smoke_1;
|
| + import 'b.dart' as smoke_2;
|
|
|
| void main() {
|
| useGeneratedCode(new StaticConfiguration(
|
| - checkedMode: false));
|
| - configureForDeployment([
|
| + checkedMode: false,
|
| + parents: {
|
| + smoke_2.XB: smoke_1.PolymerElement,
|
| + smoke_0.XA: smoke_1.PolymerElement,
|
| + },
|
| + declarations: {
|
| + smoke_2.XB: const {},
|
| + smoke_0.XA: const {},
|
| + }));
|
| + startPolymer([
|
| + i0.m_foo,
|
| + () => Polymer.register('x-A', i0.XA),
|
| + i1.m_bar,
|
| + () => Polymer.register('x-B', i1.XB),
|
| ]);
|
| - i1.main();
|
| }
|
| '''.replaceAll('\n ', '\n'),
|
| - 'a|web/index.html.0.dart': _sampleObservableOutput("A", "foo"),
|
| - 'a|web/b.dart': _sampleObservableOutput('B', 'bar'),
|
| + 'a|web/index.html.0.dart': _sampleOutput("A", "foo"),
|
| + 'a|web/b.dart': _sampleOutput('B', 'bar'),
|
| });
|
| }
|
|
|
| -String _sampleObservable(String className, String fieldName) => '''
|
| +String _sampleInput(String className, String fieldName) => '''
|
| library ${className}_$fieldName;
|
| import 'package:observe/observe.dart';
|
| -export 'package:polymer/init.dart';
|
| +import 'package:polymer/polymer.dart';
|
|
|
| class $className extends Observable {
|
| @observable int $fieldName;
|
| $className(this.$fieldName);
|
| }
|
| +
|
| +@CustomTag('x-$className')
|
| +class X${className} extends PolymerElement {
|
| + X${className}.created() : super.created();
|
| +}
|
| +@initMethod m_$fieldName() {}
|
| ''';
|
|
|
| -String _sampleObservableOutput(String className, String field,
|
| - {bool includeMain: false}) =>
|
| - "library ${className}_$field;\n"
|
| - "import 'package:observe/observe.dart';\n"
|
| - "export 'package:polymer/init.dart';\n\n"
|
| - "class $className extends ChangeNotifier {\n"
|
| - " @reflectable @observable int get $field => __\$$field; "
|
| - "int __\$$field; "
|
| - "@reflectable set $field(int value) { "
|
| - "__\$$field = notifyPropertyChange(#$field, __\$$field, value); "
|
| - "}\n"
|
| - " $className($field) : __\$$field = $field;\n"
|
| - "}\n";
|
| +
|
| +String _sampleOutput(String className, String fieldName) {
|
| + var fieldReplacement = '@reflectable @observable '
|
| + 'int get $fieldName => __\$$fieldName; '
|
| + 'int __\$$fieldName; '
|
| + '@reflectable set $fieldName(int value) { '
|
| + '__\$$fieldName = notifyPropertyChange(#$fieldName, '
|
| + '__\$$fieldName, value); }';
|
| + return '''
|
| +library ${className}_$fieldName;
|
| +import 'package:observe/observe.dart';
|
| +import 'package:polymer/polymer.dart';
|
| +
|
| +class $className extends ChangeNotifier {
|
| + $fieldReplacement
|
| + $className($fieldName) : __\$$fieldName = $fieldName;
|
| +}
|
| +
|
| +@CustomTag('x-$className')
|
| +class X${className} extends PolymerElement {
|
| + X${className}.created() : super.created();
|
| +}
|
| +@initMethod m_$fieldName() {}
|
| +''';
|
| +}
|
|
|