Skip to content
Permalink
Browse files

feature: Dart 2.x ready, works with reflectable

  • Loading branch information...
MikeMitterer committed Jun 7, 2018
1 parent feb25a7 commit ab012d395a9f22cfe0477d711765955c9d37277d
@@ -0,0 +1,15 @@
# ------------------------------------------------------------------------------
# Config for Analyzer
# More: https://pub.dartlang.org/packages/analyzer
#
# Analyzer options:
# https://www.dartlang.org/guides/language/analysis-options
#

analyzer:
strong-mode: true

# Exclude wegen https://github.com/dart-lang/sdk/issues/26420
# und https://github.com/dart-lang/test/issues/436
# exclude:
# - test/**
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -9,19 +9,14 @@ environment:
sdk: '>=1.0.0 <2.0.0'

dependencies:
browser: '>=0.10.0 <0.11.0'
dart_to_js_script_rewriter: '^0.1.0'

mustache:
path: ../../../

dev_dependencies:
reflectable: '^0.5.0'

transformers:
- dart_to_js_script_rewriter
build_runner: ^0.8.0
build_test: ^0.10.0
build_web_compilers: ^0.4.0


- reflectable:
entry_points:
- web/main.dart # The path to your main file
# formatted: true # Optional.
@@ -14,7 +14,7 @@
<title>reflection</title>
<link rel="stylesheet" href="styles.css">
<script async src="main.dart" type="application/dart"></script>
<script async src="packages/browser/dart.js"></script>
<script defer src="main.dart.js"></script>
</head>

<body>
@@ -4,6 +4,8 @@
import 'dart:html' as dom;
import 'package:mustache/mustache.dart';

import 'main.reflectable.dart';

@mustache
class Version {
final int major;
@@ -22,6 +24,8 @@ class DartLang {
}

void main() {
initializeReflectable();

final Template template = new Template(
"""
<div>
@@ -0,0 +1,29 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'main.dart' as prefix1;
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[new r.NonGenericClassMirrorImpl(r"Version", r".Version", 7, 0, const prefix0.MustacheMirrorsUsedAnnotation(), const <int>[0, 1, 7], const <int>[8, 9, 10, 11, 12, 5, 6], const <int>[], -1, {}, {}, {r"": (b) => (major, minor) => b ? new prefix1.Version(major, minor) : null}, -1, -1, const <int>[-1], null, null), new r.NonGenericClassMirrorImpl(r"DartLang", r".DartLang", 7, 1, const prefix0.MustacheMirrorsUsedAnnotation(), const <int>[2, 3, 4, 16], const <int>[8, 9, 10, 11, 12, 13, 14, 15], const <int>[], -1, {}, {}, {r"": (b) => (name, version, message) => b ? new prefix1.DartLang(name, version, message) : null}, -1, -1, const <int>[-1], null, null)], <m.DeclarationMirror>[new r.VariableMirrorImpl(r"major", 33797, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null), new r.VariableMirrorImpl(r"minor", 33797, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null), new r.VariableMirrorImpl(r"name", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null), new r.VariableMirrorImpl(r"version", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), 0, 0, 0, null), new r.VariableMirrorImpl(r"message", 33797, 1, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 0, 2, 2, 5), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 1, 2, 2, 6), new r.MethodMirrorImpl(r"", 0, 0, -1, 0, 0, const <int>[0, 1], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"==", 131074, null, -1, 4, 4, const <int>[2], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"toString", 131074, null, -1, 3, 3, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"noSuchMethod", 65538, null, null, null, null, const <int>[3], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"hashCode", 131075, null, -1, 2, 2, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"runtimeType", 131075, null, -1, 5, 5, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 2, 3, 3, 13), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 3, 0, 0, 14), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 4, 3, 3, 15), new r.MethodMirrorImpl(r"", 0, 1, -1, 1, 1, const <int>[4, 5, 6], const prefix0.MustacheMirrorsUsedAnnotation(), null)], <m.ParameterMirror>[new r.ParameterMirrorImpl(r"major", 32774, 7, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null, null, null), new r.ParameterMirrorImpl(r"minor", 32774, 7, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null, null, null), new r.ParameterMirrorImpl(r"other", 16390, 8, const prefix0.MustacheMirrorsUsedAnnotation(), null, null, null, null, null, null), new r.ParameterMirrorImpl(r"invocation", 32774, 10, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 6, 6, null, null, null), new r.ParameterMirrorImpl(r"name", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null, null, null), new r.ParameterMirrorImpl(r"version", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), 0, 0, 0, null, null, null), new r.ParameterMirrorImpl(r"message", 32774, 16, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 3, 3, null, null, null)], <Type>[prefix1.Version, prefix1.DartLang, int, String, bool, Type, Invocation], 2, {r"==": (dynamic instance) => (x) => instance == x, r"toString": (dynamic instance) => instance.toString, r"noSuchMethod": (dynamic instance) => instance.noSuchMethod, r"hashCode": (dynamic instance) => instance.hashCode, r"runtimeType": (dynamic instance) => instance.runtimeType, r"major": (dynamic instance) => instance.major, r"minor": (dynamic instance) => instance.minor, r"name": (dynamic instance) => instance.name, r"version": (dynamic instance) => instance.version, r"message": (dynamic instance) => instance.message}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -2,7 +2,7 @@ import 'package:mustache/mustache.dart';

main() {
var t = new Template('{{ foo }}');
var lambda = (_) => 'bar';
var lambda = (LambdaContext ctx) => 'bar';
var output = t.renderString({'foo': lambda}); // bar
print(output);

@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -0,0 +1,28 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[], <m.DeclarationMirror>[], <m.ParameterMirror>[], <Type>[], 0, {}, {}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -5,6 +5,16 @@ library mustache;
import 'package:reflectable/reflectable.dart';
import 'src/template.dart' as t;

class MustacheMirrorsUsedAnnotation extends Reflectable {
const MustacheMirrorsUsedAnnotation() : super(
invokingCapability,
reflectedTypeCapability
);
}

const MustacheMirrorsUsedAnnotation mustache = const MustacheMirrorsUsedAnnotation();


/// Use new Template(source) instead.
@deprecated
Template parse(String source, {bool lenient: false}) =>
@@ -70,15 +80,6 @@ abstract class LambdaContext {
Object lookup(String variableName);
}

class MustacheMirrorsUsedAnnotation extends Reflectable {
const MustacheMirrorsUsedAnnotation() : super(
invokingCapability,
reflectedTypeCapability
);
}

const MustacheMirrorsUsedAnnotation mustache = const MustacheMirrorsUsedAnnotation();

/// [TemplateException] is used to obtain the line and column numbers
/// of the token which caused parse or render to fail.
abstract class TemplateException implements Exception {
@@ -72,7 +72,7 @@ class LambdaContext implements m.LambdaContext {

if (nodes.isEmpty) return '';

if (nodes.length == 1 && nodes.first is TextNode) return nodes.first.text;
if (nodes.length == 1 && nodes.first is TextNode) return (nodes.first as TextNode).text;

return _renderer.source.substring(node.contentStart, node.contentEnd);
}
@@ -147,8 +147,11 @@ class Parser {
children.add(new TextNode(token.value, token.start, token.end));
} else {
var last = children.removeLast();
var node = new TextNode(last.text + token.value, last.start, token.end);
children.add(node);
if(last is! TextNode) {
children.add(new TextNode(token.value, token.start, token.end));
} else {
children.add(new TextNode((last as TextNode).text + token.value, last.start, token.end));
}
}
}

@@ -94,13 +94,15 @@ class Renderer extends Visitor {

if (value is Function) {
var context = new LambdaContext(node, this, isSection: false);
value = value(context);
final Function callback = value;
value = callback(context);
context.close();
}

if (value == noSuchProperty) {
if (!lenient) throw error(
'Value was missing for variable tag: ${node.name}.', node);
if (!lenient) {
throw error('Value was missing for variable tag: ${node.name}.', node);
}
} else {
var valueString = (value == null) ? '' : value.toString();
var output = !node.escape || !htmlEscapeValues
@@ -290,7 +292,7 @@ class Renderer extends Visitor {
m.TemplateException error(String message, Node node) =>
new TemplateException(message, templateName, source, node.start);

static const Map<String, String> _htmlEscapeMap = const {
static const Map<int, String> _htmlEscapeMap = const {
_AMP: '&amp;',
_LT: '&lt;',
_GT: '&gt;',
@@ -9,7 +9,11 @@ environment:
sdk: '>=1.8.0 <2.0.0'

dependencies:
reflectable: '^0.4.0'
reflectable: '^2.0.0'

dev_dependencies:
unittest: ">=0.9.0 <0.12.0"
test: any

build_runner: ^0.8.0
build_test: ^0.10.0
build_web_compilers: ^0.4.0
@@ -0,0 +1,29 @@
// This file has been generated by the reflectable package.
// https://github.com/dart-lang/reflectable.

import "dart:core";
import 'mustache_test.dart' as prefix1;
import 'package:mustache/mustache.dart' as prefix0;

// ignore:unused_import
import "package:reflectable/mirrors.dart" as m;
// ignore:unused_import
import "package:reflectable/src/reflectable_transformer_based.dart" as r;
// ignore:unused_import
import "package:reflectable/reflectable.dart" show isTransformed;

final _data = {const prefix0.MustacheMirrorsUsedAnnotation(): new r.ReflectorData(<m.TypeMirror>[new r.NonGenericClassMirrorImpl(r"Foo", r"mustache_test.Foo", 7, 0, const prefix0.MustacheMirrorsUsedAnnotation(), const <int>[0, 1, 2, 7], const <int>[8, 9, 10, 11, 12, 2, 3, 4, 5, 6], const <int>[], -1, {}, {}, {r"": (b) => () => b ? new prefix1.Foo() : null}, -1, -1, const <int>[-1], null, null)], <m.DeclarationMirror>[new r.VariableMirrorImpl(r"bar", 32773, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 1, 1, null), new r.VariableMirrorImpl(r"lambda", 32773, 0, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null), new r.MethodMirrorImpl(r"jim", 65538, 0, null, null, null, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 0, 1, 1, 3), new r.ImplicitSetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 0, 1, 1, 4), new r.ImplicitGetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 1, 2, 2, 5), new r.ImplicitSetterMirrorImpl(const prefix0.MustacheMirrorsUsedAnnotation(), 1, 2, 2, 6), new r.MethodMirrorImpl(r"", 64, 0, -1, 0, 0, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"==", 131074, null, -1, 3, 3, const <int>[2], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"toString", 131074, null, -1, 1, 1, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"noSuchMethod", 65538, null, null, null, null, const <int>[3], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"hashCode", 131075, null, -1, 4, 4, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null), new r.MethodMirrorImpl(r"runtimeType", 131075, null, -1, 5, 5, const <int>[], const prefix0.MustacheMirrorsUsedAnnotation(), null)], <m.ParameterMirror>[new r.ParameterMirrorImpl(r"_bar", 32870, 4, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 1, 1, null, null, null), new r.ParameterMirrorImpl(r"_lambda", 32870, 6, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 2, 2, null, null, null), new r.ParameterMirrorImpl(r"other", 16390, 8, const prefix0.MustacheMirrorsUsedAnnotation(), null, null, null, null, null, null), new r.ParameterMirrorImpl(r"invocation", 32774, 10, const prefix0.MustacheMirrorsUsedAnnotation(), -1, 6, 6, null, null, null)], <Type>[prefix1.Foo, String, Function, bool, int, Type, Invocation], 1, {r"==": (dynamic instance) => (x) => instance == x, r"toString": (dynamic instance) => instance.toString, r"noSuchMethod": (dynamic instance) => instance.noSuchMethod, r"hashCode": (dynamic instance) => instance.hashCode, r"runtimeType": (dynamic instance) => instance.runtimeType, r"jim": (dynamic instance) => instance.jim, r"bar": (dynamic instance) => instance.bar, r"lambda": (dynamic instance) => instance.lambda}, {r"bar=": (dynamic instance, value) => instance.bar = value, r"lambda=": (dynamic instance, value) => instance.lambda = value}, null, [])};


final _memberSymbolMap = null;

initializeReflectable() {
if (!isTransformed) {
throw new UnsupportedError(
"The transformed code is running with the untransformed "
"reflectable package. Remember to set your package-root to "
"'build/.../packages'.");
}
r.data = _data;
r.memberSymbolMap = _memberSymbolMap;
}
@@ -7,9 +7,12 @@ library mustache_specs;

import 'dart:io';
import 'dart:convert';
import 'package:unittest/unittest.dart';
import 'package:test/test.dart';

import 'package:mustache/mustache.dart';

import 'mustache_specs.reflectable.dart';

String render(source, values, {partial}) {
var resolver = null;
resolver = (name) {
@@ -22,6 +25,8 @@ String render(source, values, {partial}) {
}

main() {
initializeReflectable();

defineTests();
}

@@ -46,7 +51,8 @@ _defineGroupFromFile(filename, text) {
//Make sure that we reset the state of the Interpolation - Multiple Calls test
//as for some reason dart can run the group more than once causing the test
//to fail the second time it runs
tearDown(() => lambdas['Interpolation - Multiple Calls'].reset());

// tearDown(() => lambdas['Interpolation - Multiple Calls'].reset());

tests.forEach((t) {
var testDescription = new StringBuffer(t['name']);
@@ -104,7 +110,7 @@ class _DummyCallableWithState {
Function wrapLambda(Function f) =>
(LambdaContext ctx) => ctx.renderSource(f(ctx.source).toString());

var lambdas = {
var lambdas = <String,Function>{
'Interpolation': wrapLambda((t) => 'world'),
'Interpolation - Expansion': wrapLambda((t) => '{{planet}}'),
'Interpolation - Alternate Delimiters':
Oops, something went wrong.

0 comments on commit ab012d3

Please sign in to comment.
You can’t perform that action at this time.