From 39c03e67e600ec81d312b5809ef425695829006a Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 26 Sep 2014 17:39:27 -0700 Subject: [PATCH] refactor: rename `js2dart` to `transpiler` --- gulpfile.js | 16 +- karma-dart.conf.js | 2 +- karma-js.conf.js | 2 +- postinstall.sh | 6 +- tools/rtts-assert/API.md | 44 -- tools/rtts-assert/README.md | 1 - tools/rtts-assert/gulpfile.js | 37 -- tools/rtts-assert/karma.conf.js | 24 -- tools/rtts-assert/npm-shrinkwrap.json | 24 -- tools/rtts-assert/package.json | 31 -- tools/rtts-assert/src/assert.js | 327 --------------- tools/rtts-assert/test-main.js | 27 -- tools/rtts-assert/test/assert.spec.js | 377 ------------------ tools/{js2dart => transpiler}/LICENSE | 0 tools/{js2dart => transpiler}/gulp-tasks.js | 22 +- tools/{js2dart => transpiler}/gulp-traceur.js | 0 tools/{js2dart => transpiler}/gulpfile.js | 6 +- tools/{js2dart => transpiler}/index.js | 6 +- .../karma-traceur-preprocessor.js | 4 +- tools/{js2dart => transpiler}/package.json | 4 +- tools/{js2dart => transpiler}/pubspec.yaml | 2 +- tools/{js2dart => transpiler}/run_specs.dart | 0 .../spec/a-0-subfolder/library_spec.js | 0 .../spec/annotations_spec.js | 0 .../spec/classes_spec.js | 0 .../spec/equals_spec.js | 0 tools/{js2dart => transpiler}/spec/export.js | 0 .../spec/fixtures/annotations.dart | 0 .../spec/fixtures/facade.dart | 0 tools/{js2dart => transpiler}/spec/foo.js | 0 .../spec/functions_spec.js | 0 .../spec/imports_spec.js | 0 .../spec/runner.dart.template | 0 .../spec/types_spec.js | 0 .../src/ast/class_field.js | 0 tools/{js2dart => transpiler}/src/compiler.js | 0 .../src/dart_class_transformer.js | 0 .../src/dart_writer.js | 2 +- tools/{js2dart => transpiler}/src/parser.js | 0 39 files changed, 36 insertions(+), 928 deletions(-) delete mode 100644 tools/rtts-assert/API.md delete mode 100644 tools/rtts-assert/README.md delete mode 100644 tools/rtts-assert/gulpfile.js delete mode 100644 tools/rtts-assert/karma.conf.js delete mode 100644 tools/rtts-assert/npm-shrinkwrap.json delete mode 100644 tools/rtts-assert/package.json delete mode 100644 tools/rtts-assert/src/assert.js delete mode 100644 tools/rtts-assert/test-main.js delete mode 100644 tools/rtts-assert/test/assert.spec.js rename tools/{js2dart => transpiler}/LICENSE (100%) rename tools/{js2dart => transpiler}/gulp-tasks.js (81%) rename tools/{js2dart => transpiler}/gulp-traceur.js (100%) rename tools/{js2dart => transpiler}/gulpfile.js (69%) rename tools/{js2dart => transpiler}/index.js (93%) rename tools/{js2dart => transpiler}/karma-traceur-preprocessor.js (91%) rename tools/{js2dart => transpiler}/package.json (91%) rename tools/{js2dart => transpiler}/pubspec.yaml (93%) rename tools/{js2dart => transpiler}/run_specs.dart (100%) rename tools/{js2dart => transpiler}/spec/a-0-subfolder/library_spec.js (100%) rename tools/{js2dart => transpiler}/spec/annotations_spec.js (100%) rename tools/{js2dart => transpiler}/spec/classes_spec.js (100%) rename tools/{js2dart => transpiler}/spec/equals_spec.js (100%) rename tools/{js2dart => transpiler}/spec/export.js (100%) rename tools/{js2dart => transpiler}/spec/fixtures/annotations.dart (100%) rename tools/{js2dart => transpiler}/spec/fixtures/facade.dart (100%) rename tools/{js2dart => transpiler}/spec/foo.js (100%) rename tools/{js2dart => transpiler}/spec/functions_spec.js (100%) rename tools/{js2dart => transpiler}/spec/imports_spec.js (100%) rename tools/{js2dart => transpiler}/spec/runner.dart.template (100%) rename tools/{js2dart => transpiler}/spec/types_spec.js (100%) rename tools/{js2dart => transpiler}/src/ast/class_field.js (100%) rename tools/{js2dart => transpiler}/src/compiler.js (100%) rename tools/{js2dart => transpiler}/src/dart_class_transformer.js (100%) rename tools/{js2dart => transpiler}/src/dart_writer.js (99%) rename tools/{js2dart => transpiler}/src/parser.js (100%) diff --git a/gulpfile.js b/gulpfile.js index 0442370bee..49e51e8b3c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,9 +11,9 @@ var ejs = require('gulp-ejs'); var path = require('path'); var through2 = require('through2'); -// import js2dart build tasks -var js2dartTasks = require('./tools/js2dart/gulp-tasks'); -js2dartTasks.install(gulp); +// import transpiler build tasks +var transpilerTasks = require('./tools/transpiler/gulp-tasks'); +transpilerTasks.install(gulp); var js2es5Options = { annotations: true, // parse annotations @@ -24,14 +24,14 @@ var js2es5Options = { typeAssertions: true }; -var js2dartOptions = { +var transpilerOptions = { annotations: true, // parse annotations types: true, // parse types script: false, // parse as a module outputLanguage: 'dart' }; -var gulpTraceur = require('./tools/js2dart/gulp-traceur'); +var gulpTraceur = require('./tools/transpiler/gulp-traceur'); function resolveModuleName(fileName) { var moduleName = fileName @@ -62,7 +62,7 @@ function createJsRuntimeTask(isWatch) { var sourceTypeConfigs = { dart: { compiler: function() { - return gulpTraceur(js2dartOptions, resolveModuleName); + return gulpTraceur(transpilerOptions, resolveModuleName); }, transpileSrc: ['modules/**/*.js'], htmlSrc: ['modules/*/src/**/*.html'], @@ -177,13 +177,13 @@ gulp.task('serve', connect.server({ // -------------- // general targets -gulp.task('clean', ['js2dart/clean', 'modules/clean']); +gulp.task('clean', ['transpiler/clean', 'modules/clean']); gulp.task('build', ['jsRuntime/build', 'modules/build.dart', 'modules/build.js']); gulp.task('watch', function() { // parallel is important as both streams are infinite! - runSequence(['js2dart/test/watch', 'js2dart/src/watch']); + runSequence(['transpiler/test/watch', 'transpiler/src/watch']); var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true); var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true); return mergeStreams(dartModuleWatch, jsModuleWatch, createJsRuntimeTask(true)); diff --git a/karma-dart.conf.js b/karma-dart.conf.js index 81643b456e..9e820d0a4a 100644 --- a/karma-dart.conf.js +++ b/karma-dart.conf.js @@ -57,5 +57,5 @@ module.exports = function(config) { }); - config.plugins.push(require('./tools/js2dart/karma-traceur-preprocessor')); + config.plugins.push(require('./tools/transpiler/karma-traceur-preprocessor')); }; diff --git a/karma-js.conf.js b/karma-js.conf.js index 5b1ec0c654..c4237c5ad6 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -45,5 +45,5 @@ module.exports = function(config) { browsers: ['Chrome'] }); - config.plugins.push(require('./tools/js2dart/karma-traceur-preprocessor')); + config.plugins.push(require('./tools/transpiler/karma-traceur-preprocessor')); }; diff --git a/postinstall.sh b/postinstall.sh index 13d054afe6..f7c5192fc6 100755 --- a/postinstall.sh +++ b/postinstall.sh @@ -1,7 +1,7 @@ #! /bin/sh git submodule init && git submodule update -rm node_modules/js2dart -ln -s ../tools/js2dart node_modules/js2dart +rm node_modules/transpiler +ln -s ../tools/transpiler node_modules/transpiler -(cd tools/js2dart; npm install) +(cd tools/transpiler; npm install) diff --git a/tools/rtts-assert/API.md b/tools/rtts-assert/API.md deleted file mode 100644 index dbe350fdc7..0000000000 --- a/tools/rtts-assert/API.md +++ /dev/null @@ -1,44 +0,0 @@ -// Asserting APIs: -// - generated by Traceur (based on type annotations) -// - can be also used in tests for instance -assert.type(something, Type); -assert.returnType(returnValue, Type); -assert.argumentTypes(firstArg, Type, secondArg, Type); - -// this can be used anywhere in the code -// (useful inside test, when we don't wanna define an interface) -assert(value).is(...) - - -// Custom type assert: -// - i have a custom type -// - adding an assert methos -assert.define(MyUser, function(value) { - assert(value).is(Type, Type2); // or - assert(value, 'name').is(assert.string); - assert(value, 'contact').is(assert.structure({ - email: assert.string, - cell: assert.string - })); - assert(value, 'contacts').is(assert.arrayOf(assert.structure({email: assert.string}))); -}); - - - -// Define interface (an empty type with assert method) -// - returns an empty class with assert method -var Email = assert.define('IEmail', function(value) { - assert(value).is(String); - - if (value.indexOf('@') !== -1) { - assert.fail('has to contain "@"'); - } -}); - - -// Predefined types -assert.string -assert.number -assert.boolean -assert.arrayOf(...types) -assert.structure(object) diff --git a/tools/rtts-assert/README.md b/tools/rtts-assert/README.md deleted file mode 100644 index 784709602d..0000000000 --- a/tools/rtts-assert/README.md +++ /dev/null @@ -1 +0,0 @@ -http://angular.github.io/assert/ diff --git a/tools/rtts-assert/gulpfile.js b/tools/rtts-assert/gulpfile.js deleted file mode 100644 index 117c81eb9c..0000000000 --- a/tools/rtts-assert/gulpfile.js +++ /dev/null @@ -1,37 +0,0 @@ -var gulp = require('gulp'); -var pipe = require('pipe/gulp'); -var traceur = require('gulp-traceur'); - - -var path = { - src: './src/**/*.js', -}; - - -// TRANSPILE ES6 -gulp.task('build_source_amd', function() { - gulp.src(path.src) - .pipe(traceur(pipe.traceur())) - .pipe(gulp.dest('dist/amd')); -}); - -gulp.task('build_source_cjs', function() { - gulp.src(path.src) - .pipe(traceur(pipe.traceur({modules: 'commonjs'}))) - .pipe(gulp.dest('dist/cjs')); -}); - -gulp.task('build_source_es6', function() { - gulp.src(path.src) - .pipe(traceur(pipe.traceur({outputLanguage: 'es6'}))) - .pipe(gulp.dest('dist/es6')); -}); - -gulp.task('build_dist', ['build_source_cjs', 'build_source_amd', 'build_source_es6']); -gulp.task('build', ['build_dist']); - - -// WATCH FILES FOR CHANGES -gulp.task('watch', function() { - gulp.watch(path.src, ['build']); -}); diff --git a/tools/rtts-assert/karma.conf.js b/tools/rtts-assert/karma.conf.js deleted file mode 100644 index ab73d79824..0000000000 --- a/tools/rtts-assert/karma.conf.js +++ /dev/null @@ -1,24 +0,0 @@ -var sharedConfig = require('pipe/karma'); - -module.exports = function(config) { - sharedConfig(config); - - config.set({ - // list of files / patterns to load in the browser - files: [ - 'test-main.js', - - {pattern: 'src/**/*.js', included: false}, - {pattern: 'test/**/*.js', included: false} - ], - - usePolling: true, - - preprocessors: { - 'src/**/*.js': ['traceur'], - 'test/**/*.js': ['traceur'] - } - }); - - config.sauceLabs.testName = 'assert'; -}; diff --git a/tools/rtts-assert/npm-shrinkwrap.json b/tools/rtts-assert/npm-shrinkwrap.json deleted file mode 100644 index d5e8d94fec..0000000000 --- a/tools/rtts-assert/npm-shrinkwrap.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "rtts-assert", - "version": "0.0.0", - "dependencies": { - "gulp-traceur": { - "version": "0.4.0", - "from": "gulp-traceur@0.4.0", - "dependencies": { - "gulp-util": { - "version": "2.2.5", - "from": "gulp-util@2.2.5" - }, - "through2": { - "version": "0.4.0", - "from": "through2@0.4.0" - }, - "traceur": { - "version": "0.0..0", - "from": "git://github.com/vojtajina/traceur-compiler#add-es6-pure-transformer-dist" - } - } - } - } -} diff --git a/tools/rtts-assert/package.json b/tools/rtts-assert/package.json deleted file mode 100644 index 3a56cf734b..0000000000 --- a/tools/rtts-assert/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "rtts-assert", - "version": "0.0.1", - "description": "A type assertion library for Traceur.", - "main": "./dist/cjs/assert.js", - "homepage": "https://github.com/angular/assert", - "repository": { - "type": "git", - "url": "git://github.com/angular/assert.git" - }, - "bugs": { - "url": "https://github.com/angular/assert/issues" - }, - "dependencies": {}, - "devDependencies": { - "gulp": "^3.5.6", - "gulp-connect": "~1.0.5", - "gulp-traceur": "~0.4.0", - "karma": "^0.12.1", - "karma-chrome-launcher": "^0.1.2", - "karma-jasmine": "^0.2.2", - "karma-requirejs": "^0.2.1", - "karma-traceur-preprocessor": "^0.2.2", - "pipe": "git://github.com/angular/pipe#remove-transitive-deps" - }, - "scripts": { - "test": "karma start --single-run" - }, - "author": "Vojta Jína ", - "license": "Apache-2.0" -} diff --git a/tools/rtts-assert/src/assert.js b/tools/rtts-assert/src/assert.js deleted file mode 100644 index da6ea51a64..0000000000 --- a/tools/rtts-assert/src/assert.js +++ /dev/null @@ -1,327 +0,0 @@ -// TODO(vojta): -// - extract into multiple files -// - different error types -// - simplify/humanize error messages -// - throw when invalid input (such as odd number of args into assert.argumentTypes) - -var POSITION_NAME = ['', '1st', '2nd', '3rd']; -function argPositionName(i) { - var position = (i / 2) + 1; - - return POSITION_NAME[position] || (position + 'th'); -} - -var primitives = $traceurRuntime.type; - -function assertArgumentTypes(...params) { - var actual, type; - var currentArgErrors; - var errors = []; - var msg; - - for (var i = 0, l = params.length; i < l; i = i + 2) { - actual = params[i]; - type = params[i + 1]; - - currentArgErrors = []; - - // currentStack = []; - // - - if (!isType(actual, type, currentArgErrors)) { - - // console.log(JSON.stringify(errors, null, ' ')); - // TODO(vojta): print "an instance of" only if T starts with uppercase. - errors.push(argPositionName(i) + ' argument has to be an instance of ' + prettyPrint(type) + ', got ' + prettyPrint(actual)); - if (currentArgErrors.length) { - errors.push(currentArgErrors); - } - } - } - - if (errors.length) { - throw new Error('Invalid arguments given!\n' + formatErrors(errors)); - } -} - -function prettyPrint(value) { - if (typeof value === 'undefined') { - return 'undefined'; - } - - if (typeof value === 'string') { - return '"' + value + '"'; - } - - if (typeof value === 'boolean') { - return value.toString(); - } - - if (value === null) { - return 'null'; - } - - if (typeof value === 'object') { - if (value.map) { - return '[' + value.map(prettyPrint).join(', ') + ']'; - } - - var properties = Object.keys(value); - return '{' + properties.map((p) => p + ': ' + prettyPrint(value[p])).join(', ') + '}'; - } - - return value.__assertName || value.name || value.toString(); -} - -function isType(value, T, errors) { - - if (T === primitives.void) { - return typeof value === 'undefined'; - } - - if (T === primitives.any || value === null) { - return true; - } - - if (T === primitives.string) { - return typeof value === 'string'; - } - - if (T === primitives.number) { - return typeof value === 'number'; - } - - if (T === primitives.boolean) { - return typeof value === 'boolean'; - } - - // var parentStack = currentStack; - // currentStack = []; - - // shouldnt this create new stack? - if (typeof T.assert === 'function') { - var parentStack = currentStack; - var isValid; - currentStack = errors; - try { - isValid = T.assert(value) ; - } catch (e) { - fail(e.message); - isValid = false; - } - - currentStack = parentStack; - - if (typeof isValid === 'undefined') { - isValid = errors.length === 0; - } - - return isValid; - - // if (!currentStack.length) { - // currentStack = parentStack; - // return []; - // } - // var res = currentStack; - // currentStack = parentStack; - // return ['not instance of ' + prettyPrint(T), res]; - } - - return value instanceof T; - - // if (!(value instanceof T)) { - // fail('not instance of ' + prettyPrint(T)); - // } - - // var res = currentStack; - // currentStack = parentStack; - - // return res; -} - -function formatErrors(errors, indent = ' ') { - return errors.map((e) => { - if (typeof e === 'string') return indent + '- ' + e; - return formatErrors(e, indent + ' '); - }).join('\n'); -} - - -// assert a type of given value and throw if does not pass -function type(actual, T) { - var errors = []; - // currentStack = []; - - if (!isType(actual, T, errors)) { - // console.log(JSON.stringify(errors, null, ' ')); - // TODO(vojta): print "an instance of" only if T starts with uppercase. - var msg = 'Expected an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!'; - if (errors.length) { - msg += '\n' + formatErrors(errors); - } - - throw new Error(msg); - } -} - -function returnType(actual, T) { - var errors = []; - // currentStack = []; - - if (!isType(actual, T, errors)) { - // console.log(JSON.stringify(errors, null, ' ')); - // TODO(vojta): print "an instance of" only if T starts with uppercase. - var msg = 'Expected to return an instance of ' + prettyPrint(T) + ', got ' + prettyPrint(actual) + '!'; - if (errors.length) { - msg += '\n' + formatErrors(errors); - } - - throw new Error(msg); - } - - return actual; -} - - -// TODO(vojta): define these with DSL? -var string = define('string', function(value) { - return typeof value === 'string'; -}); - -// function string() {} -// string.assert = function(value) { -// return typeof value === 'string'; -// }; - -var boolean = define('boolean', function(value) { - return typeof value === 'boolean'; -}); -// function boolean() {} -// boolean.assert = function(value) { -// return typeof value === 'boolean'; -// }; - -var number = define('number', function(value) { - return typeof value === 'number'; -}); -// function number() {} -// number.assert = function(value) { -// return typeof value === 'number'; -// }; - - -function arrayOf(...types) { - return assert.define('array of ' + types.map(prettyPrint).join('/'), function(value) { - if (assert(value).is(Array)) { - for (var item of value) { - assert(item).is(...types); - } - } - }); -} - -function structure(definition) { - var properties = Object.keys(definition); - return assert.define('object with properties ' + properties.join(', '), function(value) { - if (assert(value).is(Object)) { - for (var property of properties) { - assert(value[property]).is(definition[property]); - } - } - }) -} - - - -// I'm sorry, bad global state... to make the API nice ;-) -var currentStack = []; - -function fail(message) { - currentStack.push(message); -} - -function define(classOrName, check) { - var cls = classOrName; - - if (typeof classOrName === 'string') { - cls = function() {}; - cls.__assertName = classOrName; - } - - cls.assert = function(value) { - // var parentStack = currentStack; - - // currentStack = []; - - return check(value); - - // if (currentStack.length) { - // parentStack.push(currentStack) - // } - // currentStack = parentStack; - }; - - return cls; -} - - - -function assert(value) { - return { - is: function is(...types) { - // var errors = [] - var allErrors = []; - var errors; - - for (var type of types) { - errors = []; - - if (isType(value, type, errors)) { - return true; - } - - // if no errors, merge multiple "is not instance of " into x/y/z ? - allErrors.push(prettyPrint(value) + ' is not instance of ' + prettyPrint(type)) - if (errors.length) { - allErrors.push(errors); - } - } - - // if (types.length > 1) { - // currentStack.push(['has to be ' + types.map(prettyPrint).join(' or '), ...allErrors]); - // } else { - currentStack.push(...allErrors); - // } - return false; - } - }; -} - - -// PUBLIC API - -// asserting API - -// throw if no type provided -assert.type = type; - -// throw if odd number of args -assert.argumentTypes = assertArgumentTypes; -assert.returnType = returnType; - - -// define AP; -assert.define = define; -assert.fail = fail; - -// primitive value type; -assert.string = string; -assert.number = number; -assert.boolean = boolean; - -// custom types -assert.arrayOf = arrayOf; -assert.structure = structure; - - -export {assert} diff --git a/tools/rtts-assert/test-main.js b/tools/rtts-assert/test-main.js deleted file mode 100644 index 6554db4a00..0000000000 --- a/tools/rtts-assert/test-main.js +++ /dev/null @@ -1,27 +0,0 @@ -var allTestFiles = []; -var TEST_REGEXP = /\.spec\.js$/; - -var pathToModule = function(path) { - return path.replace(/^\/base\//, '').replace(/\.js$/, ''); -}; - -Object.keys(window.__karma__.files).forEach(function(file) { - if (TEST_REGEXP.test(file)) { - // Normalize paths to RequireJS module names. - allTestFiles.push(pathToModule(file)); - } -}); - -require.config({ - // Karma serves files under /base, which is the basePath from your config file - baseUrl: '/base', - paths: { - 'assert': 'src/assert' - }, - - // Dynamically load all test files and ES6 polyfill. - deps: allTestFiles, - - // we have to kickoff jasmine, as it is asynchronous - callback: window.__karma__.start -}); diff --git a/tools/rtts-assert/test/assert.spec.js b/tools/rtts-assert/test/assert.spec.js deleted file mode 100644 index 0a0b0e5300..0000000000 --- a/tools/rtts-assert/test/assert.spec.js +++ /dev/null @@ -1,377 +0,0 @@ -// # Assert.js -// A run-time type assertion library for JavaScript. Designed to be used with [Traceur](https://github.com/google/traceur-compiler). - - -// - [Basic Type Check](#basic-type-check) -// - [Custom Check](#custom-check) -// - [Primitive Values](#primitive-values) -// - [Describing more complex types](#describing-more-complex-types) -// - [assert.arrayOf](#assert-arrayof) -// - [assert.structure](#assert-structure) -// - [Integrating with Traceur](#integrating-with-traceur) - -import {assert} from 'assert'; - - - -// ## Basic Type Check -// By default, `instanceof` is used to check the type. -// -// Note that you can use `assert.type()` in unit tests or anywhere in your code. -// Most of the time, you will use it with Traceur. -// Jump to the [Traceur section](#integrating-with-traceur) to see an example of that. -describe('basic type check', function() { - - class Type {} - - it('should pass', function() { - assert.type(new Type(), Type); - }); - - - it('should fail', function() { - expect(() => assert.type(123, Type)) - .toThrowError('Expected an instance of Type, got 123!'); - }); - - - it('should allow null', function() { - assert.type(null, Type); - }); -}); - - - -// ## Custom Check -// Often, `instanceof` is not flexible enough. -// In that case, your type can define its own `assert` method which will be used instead. -// -// See [Describing More Complex Types](#describing-more-complex-types) for examples how to -// define custom checks using `assert.define()`. -describe('custom check', function() { - - class Type {} - - // the basic check can just return true/false, without specifying any reason - it('should pass when returns true', function() { - Type.assert = function(value) { - return true; - }; - - assert.type({}, Type); - }); - - - it('should fail when returns false', function() { - Type.assert = function(value) { - return false; - }; - - expect(() => assert.type({}, Type)) - .toThrowError('Expected an instance of Type, got {}!'); - }); - - - // Using `assert.fail()` allows to report even multiple errors. - it('should fail when calls assert.fail()', function() { - Type.assert = function(value) { - assert.fail('not smart enough'); - assert.fail('not blue enough'); - }; - - expect(() => assert.type({}, Type)) - .toThrowError('Expected an instance of Type, got {}!\n' + - ' - not smart enough\n' + - ' - not blue enough'); - }); - - - it('should fail when throws an exception', function() { - Type.assert = function(value) { - throw new Error('not long enough'); - }; - - expect(function() { - assert.type(12345, Type); - }).toThrowError('Expected an instance of Type, got 12345!\n' + - ' - not long enough'); - }); -}); - - - -// ## Primitive Values -// You don't want to check primitive values (such as strings, numbers, or booleans) using `typeof` rather than -// `instanceof`. -// -// Again, you probably won't write this code and rather use Traceur to do it for you, simply based on type annotations. -describe('primitive value check', function() { - var primitive = $traceurRuntime.type; - - describe('string', function() { - - it('should pass', function() { - assert.type('xxx', primitive.string); - }); - - - it('should fail', function() { - expect(() => assert.type(12345, primitive.string)) - .toThrowError('Expected an instance of string, got 12345!'); - }); - - it('should allow null', function() { - assert.type(null, primitive.string); - }); - }); - - - describe('number', function() { - - it('should pass', function() { - assert.type(123, primitive.number); - }); - - - it('should fail', function() { - expect(() => assert.type(false, primitive.number)) - .toThrowError('Expected an instance of number, got false!'); - }); - - it('should allow null', function() { - assert.type(null, primitive.number); - }); - }); - - - describe('boolean', function() { - - it('should pass', function() { - assert.type(true, primitive.boolean); - assert.type(false, primitive.boolean); - }); - - - it('should fail', function() { - expect(() => assert.type(123, primitive.boolean)) - .toThrowError('Expected an instance of boolean, got 123!'); - }); - - it('should allow null', function() { - assert.type(null, primitive.boolean); - }); - }); -}); - - - -// ## Describing more complex types -// -// Often, a simple type check using `instanceof` or `typeof` is not enough. -// That's why you can define custom checks using this DSL. -// The goal was to make them easy to compose and as descriptive as possible. -// Of course you can write your own DSL on the top of this. -describe('define', function() { - - // If the first argument to `assert.define()` is a type (function), it will define `assert` method on that function. - // - // In this example, being a type of Type means being a either a function or object. - it('should define assert for an existing type', function() { - class Type {} - - assert.define(Type, function(value) { - assert(value).is(Function, Object); - }); - - assert.type({}, Type); - assert.type(function() {}, Type); - expect(() => assert.type('str', Type)) - .toThrowError('Expected an instance of Type, got "str"!\n' + - ' - "str" is not instance of Function\n' + - ' - "str" is not instance of Object'); - }); - - - // If the first argument to `assert.define()` is a string, - // it will create an interface - basically an empty class with `assert` method. - it('should define an interface', function() { - var User = assert.define('MyUser', function(user) { - assert(user).is(Object); - }); - - assert.type({}, User); - expect(() => assert.type(12345, User)) - .toThrowError('Expected an instance of MyUser, got 12345!\n' + - ' - 12345 is not instance of Object'); - }); - - - // Here are a couple of more APIs to describe your custom types... - // - // ### assert.arrayOf - // Checks if the value is an array and if so, it checks whether all the items are one the given types. - // These types can be composed types, not just simple ones. - describe('arrayOf', function() { - - var Titles = assert.define('ListOfTitles', function(value) { - assert(value).is(assert.arrayOf(assert.string, assert.number)); - }); - - it('should pass', function () { - assert.type(['one', 55, 'two'], Titles); - }); - - - it('should fail when non-array given', function () { - expect(() => assert.type('foo', Titles)) - .toThrowError('Expected an instance of ListOfTitles, got "foo"!\n' + - ' - "foo" is not instance of array of string/number\n' + - ' - "foo" is not instance of Array'); - }); - - - it('should fail when an invalid item in the array', function () { - expect(() => assert.type(['aaa', true], Titles)) - .toThrowError('Expected an instance of ListOfTitles, got ["aaa", true]!\n' + - ' - ["aaa", true] is not instance of array of string/number\n' + - ' - true is not instance of string\n' + - ' - true is not instance of number'); - }); - }); - - - // ### assert.structure - // Similar to `assert.arrayOf` which checks a content of an array, - // `assert.structure` checks if the value is an object with specific properties. - describe('structure', function() { - - var User = assert.define('MyUser', function(value) { - assert(value).is(assert.structure({ - name: assert.string, - age: assert.number - })); - }); - - it('should pass', function () { - assert.type({name: 'Vojta', age: 28}, User); - }); - - - it('should fail when non-object given', function () { - expect(() => assert.type(123, User)) - .toThrowError('Expected an instance of MyUser, got 123!\n' + - ' - 123 is not instance of object with properties name, age\n' + - ' - 123 is not instance of Object'); - }); - - - it('should fail when an invalid property', function () { - expect(() => assert.type({name: 'Vojta', age: true}, User)) - .toThrowError('Expected an instance of MyUser, got {name: "Vojta", age: true}!\n' + - ' - {name: "Vojta", age: true} is not instance of object with properties name, age\n' + - ' - true is not instance of number'); - }); - }); -}); - - - -// ## Integrating with Traceur -// -// Manually calling `assert.type()` in your code is cumbersome. Most of the time, you'll want to -// have Traceur add the calls to `assert.type()` to your code based on type annotations. -// -// This has several advantages: -// - it's shorter and nicer, -// - you can easily ignore it when generating production code. -// -// You'll need to run Traceur with `--types=true --type-assertions=true --type-assertion-module="path/to/assert"`. -describe('Traceur', function() { - - describe('arguments', function() { - - function reverse(str: string) { - return str ? reverse(str.substring(1)) + str[0] : '' - } - - it('should pass', function() { - expect(reverse('angular')).toBe('ralugna'); - }); - - - it('should fail', function() { - expect(() => reverse(123)) - .toThrowError('Invalid arguments given!\n' + - ' - 1st argument has to be an instance of string, got 123'); - }); - }); - - - describe('return value', function() { - - function foo(bar): number { - return bar; - } - - it('should pass', function() { - expect(foo(123)).toBe(123); - }); - - - it('should fail', function() { - expect(() => foo('bar')) - .toThrowError('Expected to return an instance of number, got "bar"!'); - }); - }); - - - describe('variables', function() { - - it('should pass', function() { - var count:number = 1; - }); - - - it('should fail', function() { - expect(() => { - var count: number = true; - }).toThrowError('Expected an instance of number, got true!'); - }); - }); - - - describe('void', function() { - function foo(bar): void { - return bar; - } - - it('should pass when not defined', function() { - function nonReturn(): void {} - function returnNothing(): void { return; } - function returnUndefined(): void { return undefined; } - - foo(); - foo(undefined); - nonReturn(); - returnNothing(); - returnUndefined(); - }); - - - it('should fail when a value returned', function() { - expect(() => foo('bar')) - .toThrowError('Expected to return an instance of voidType, got "bar"!'); - }); - - - it('should fail when null returned', function() { - expect(() => foo(null)) - .toThrowError('Expected to return an instance of voidType, got null!'); - }); - }); -}); - - -//
-// This documentation was generated from [assert.spec.js](https://github.com/vojtajina/assert/blob/master/test/assert.spec.js) using [Docco](http://jashkenas.github.io/docco/). -//
diff --git a/tools/js2dart/LICENSE b/tools/transpiler/LICENSE similarity index 100% rename from tools/js2dart/LICENSE rename to tools/transpiler/LICENSE diff --git a/tools/js2dart/gulp-tasks.js b/tools/transpiler/gulp-tasks.js similarity index 81% rename from tools/js2dart/gulp-tasks.js rename to tools/transpiler/gulp-tasks.js index de2cfac5ad..0b42378425 100644 --- a/tools/js2dart/gulp-tasks.js +++ b/tools/transpiler/gulp-tasks.js @@ -12,7 +12,7 @@ var traceurDir = baseDir+'/../traceur'; var buildDir = baseDir + '/build'; var paths = { - js2dartSrc: baseDir + '/src/**/*.js', + transpilerSrc: baseDir + '/src/**/*.js', specTranspile: baseDir + '/spec/**/*.js', specTemplates: baseDir + '/spec/**/*.template', specCopy: baseDir + '/spec/**/*.dart' @@ -32,31 +32,31 @@ function install(gulp) { outputLanguage: 'dart' }; - gulp.task('js2dart/clean', function() { + gulp.task('transpiler/clean', function() { return gulp.src(buildDir, {read: false}) .pipe(clean()); }); - gulp.task('js2dart/test/build', function() { + gulp.task('transpiler/test/build', function() { return mergeStreams(specTranspile(false), specCopy(false), specRunner(false)); }); - gulp.task('js2dart/test/run', shell.task([ + gulp.task('transpiler/test/run', shell.task([ 'cd '+baseDir+' && dart --checked run_specs.dart' ])); - gulp.task('js2dart/test', function(done) { - runSequence('js2dart/test/build', 'js2dart/test/run', done); + gulp.task('transpiler/test', function(done) { + runSequence('transpiler/test/build', 'transpiler/test/run', done); }); - gulp.task('js2dart/src/watch', function(done) { - return watch(paths.js2dartSrc, function(changes, done) { + gulp.task('transpiler/src/watch', function(done) { + return watch(paths.transpilerSrc, function(changes, done) { gulpTraceur.sourcesChanged(); - runSequence('js2dart/test', done); + runSequence('transpiler/test', done); }); }); - gulp.task('js2dart/test/watch', function(done) { + gulp.task('transpiler/test/watch', function(done) { var streams = []; streams.push(specTranspile(true) .on('data', specRunner)); @@ -65,7 +65,7 @@ function install(gulp) { streams.forEach(function(stream) { stream.on('error', done); stream.on('data', function() { - runSequence('js2dart/test/run'); + runSequence('transpiler/test/run'); }); }); }); diff --git a/tools/js2dart/gulp-traceur.js b/tools/transpiler/gulp-traceur.js similarity index 100% rename from tools/js2dart/gulp-traceur.js rename to tools/transpiler/gulp-traceur.js diff --git a/tools/js2dart/gulpfile.js b/tools/transpiler/gulpfile.js similarity index 69% rename from tools/js2dart/gulpfile.js rename to tools/transpiler/gulpfile.js index 636631ef00..d3531ab79d 100644 --- a/tools/js2dart/gulpfile.js +++ b/tools/transpiler/gulpfile.js @@ -7,12 +7,12 @@ var mergeStreams = require('event-stream').merge; tasks.install(gulp); gulp.task('test', function() { - return runSequence('js2dart/test'); + return runSequence('transpiler/test'); }); -gulp.task('clean', ['js2dart/clean']); +gulp.task('clean', ['transpiler/clean']); gulp.task('watch', function(done) { // parallel is important as both streams are infinite! - runSequence(['js2dart/test/watch', 'js2dart/src/watch'], done); + runSequence(['transpiler/test/watch', 'transpiler/src/watch'], done); }); \ No newline at end of file diff --git a/tools/js2dart/index.js b/tools/transpiler/index.js similarity index 93% rename from tools/js2dart/index.js rename to tools/transpiler/index.js index 51d48535db..f5e7659f6b 100644 --- a/tools/js2dart/index.js +++ b/tools/transpiler/index.js @@ -7,7 +7,7 @@ var traceur = require('traceur'); exports.RUNTIME_PATH = traceur.RUNTIME_PATH; var TRACEUR_PATH = traceur.RUNTIME_PATH.replace('traceur-runtime.js', 'traceur.js'); -var SELF_SOURCE_REGEX = /js2dart\/src/; +var SELF_SOURCE_REGEX = /transpiler\/src/; var SELF_COMPILE_OPTIONS = { modules: 'register', moduleName: true, @@ -41,7 +41,7 @@ exports.compile = function compile(options, paths, source) { var localOptions = extend(options, { moduleName: moduleName }); - var CompilerCls = System.get('js2dart/src/compiler').Compiler; + var CompilerCls = System.get('transpiler/src/compiler').Compiler; return (new CompilerCls(localOptions)).compile(source, inputPath, outputPath); }; @@ -63,7 +63,7 @@ function loadModule(filepath, transpile) { if (transpile) { var moduleName = filepath - .replace(__dirname, 'js2dart') + .replace(__dirname, 'transpiler') .replace(/\.\w*$/, ''); data = (new traceur.NodeCompiler( extend(SELF_COMPILE_OPTIONS, { moduleName: moduleName } ) diff --git a/tools/js2dart/karma-traceur-preprocessor.js b/tools/transpiler/karma-traceur-preprocessor.js similarity index 91% rename from tools/js2dart/karma-traceur-preprocessor.js rename to tools/transpiler/karma-traceur-preprocessor.js index f7a247242f..03ac8f7a86 100644 --- a/tools/js2dart/karma-traceur-preprocessor.js +++ b/tools/transpiler/karma-traceur-preprocessor.js @@ -1,4 +1,4 @@ -var js2dart = require('./index.js'); +var transpiler = require('./index.js'); module.exports = { 'preprocessor:traceur': ['factory', createJs2DartPreprocessor] @@ -14,7 +14,7 @@ function createJs2DartPreprocessor(logger, basePath, config) { if (config.transformPath) { file.path = config.transformPath(file.originalPath); } - done(null, js2dart.compile(config.options, { + done(null, transpiler.compile(config.options, { inputPath: file.originalPath, moduleName: moduleName }, content)); diff --git a/tools/js2dart/package.json b/tools/transpiler/package.json similarity index 91% rename from tools/js2dart/package.json rename to tools/transpiler/package.json index c7ab919ef6..d456e05c93 100644 --- a/tools/js2dart/package.json +++ b/tools/transpiler/package.json @@ -1,10 +1,10 @@ { - "name": "js2dart", + "name": "transpiler", "version": "0.0.0", "description": "Compile JavaScript to Dart so that you can compile it back to JavaScript and run.", "main": "index.js", "scripts": { - "test": "gulp js2dart/test", + "test": "gulp transpiler/test", "postinstall": "pub install" }, "author": "Vojta Jina ", diff --git a/tools/js2dart/pubspec.yaml b/tools/transpiler/pubspec.yaml similarity index 93% rename from tools/js2dart/pubspec.yaml rename to tools/transpiler/pubspec.yaml index 992d05d487..90a31db5a0 100644 --- a/tools/js2dart/pubspec.yaml +++ b/tools/transpiler/pubspec.yaml @@ -1,4 +1,4 @@ -name: js2dart +name: transpiler version: 0.0.0 authors: - Vojta Jina diff --git a/tools/js2dart/run_specs.dart b/tools/transpiler/run_specs.dart similarity index 100% rename from tools/js2dart/run_specs.dart rename to tools/transpiler/run_specs.dart diff --git a/tools/js2dart/spec/a-0-subfolder/library_spec.js b/tools/transpiler/spec/a-0-subfolder/library_spec.js similarity index 100% rename from tools/js2dart/spec/a-0-subfolder/library_spec.js rename to tools/transpiler/spec/a-0-subfolder/library_spec.js diff --git a/tools/js2dart/spec/annotations_spec.js b/tools/transpiler/spec/annotations_spec.js similarity index 100% rename from tools/js2dart/spec/annotations_spec.js rename to tools/transpiler/spec/annotations_spec.js diff --git a/tools/js2dart/spec/classes_spec.js b/tools/transpiler/spec/classes_spec.js similarity index 100% rename from tools/js2dart/spec/classes_spec.js rename to tools/transpiler/spec/classes_spec.js diff --git a/tools/js2dart/spec/equals_spec.js b/tools/transpiler/spec/equals_spec.js similarity index 100% rename from tools/js2dart/spec/equals_spec.js rename to tools/transpiler/spec/equals_spec.js diff --git a/tools/js2dart/spec/export.js b/tools/transpiler/spec/export.js similarity index 100% rename from tools/js2dart/spec/export.js rename to tools/transpiler/spec/export.js diff --git a/tools/js2dart/spec/fixtures/annotations.dart b/tools/transpiler/spec/fixtures/annotations.dart similarity index 100% rename from tools/js2dart/spec/fixtures/annotations.dart rename to tools/transpiler/spec/fixtures/annotations.dart diff --git a/tools/js2dart/spec/fixtures/facade.dart b/tools/transpiler/spec/fixtures/facade.dart similarity index 100% rename from tools/js2dart/spec/fixtures/facade.dart rename to tools/transpiler/spec/fixtures/facade.dart diff --git a/tools/js2dart/spec/foo.js b/tools/transpiler/spec/foo.js similarity index 100% rename from tools/js2dart/spec/foo.js rename to tools/transpiler/spec/foo.js diff --git a/tools/js2dart/spec/functions_spec.js b/tools/transpiler/spec/functions_spec.js similarity index 100% rename from tools/js2dart/spec/functions_spec.js rename to tools/transpiler/spec/functions_spec.js diff --git a/tools/js2dart/spec/imports_spec.js b/tools/transpiler/spec/imports_spec.js similarity index 100% rename from tools/js2dart/spec/imports_spec.js rename to tools/transpiler/spec/imports_spec.js diff --git a/tools/js2dart/spec/runner.dart.template b/tools/transpiler/spec/runner.dart.template similarity index 100% rename from tools/js2dart/spec/runner.dart.template rename to tools/transpiler/spec/runner.dart.template diff --git a/tools/js2dart/spec/types_spec.js b/tools/transpiler/spec/types_spec.js similarity index 100% rename from tools/js2dart/spec/types_spec.js rename to tools/transpiler/spec/types_spec.js diff --git a/tools/js2dart/src/ast/class_field.js b/tools/transpiler/src/ast/class_field.js similarity index 100% rename from tools/js2dart/src/ast/class_field.js rename to tools/transpiler/src/ast/class_field.js diff --git a/tools/js2dart/src/compiler.js b/tools/transpiler/src/compiler.js similarity index 100% rename from tools/js2dart/src/compiler.js rename to tools/transpiler/src/compiler.js diff --git a/tools/js2dart/src/dart_class_transformer.js b/tools/transpiler/src/dart_class_transformer.js similarity index 100% rename from tools/js2dart/src/dart_class_transformer.js rename to tools/transpiler/src/dart_class_transformer.js diff --git a/tools/js2dart/src/dart_writer.js b/tools/transpiler/src/dart_writer.js similarity index 99% rename from tools/js2dart/src/dart_writer.js rename to tools/transpiler/src/dart_writer.js index e0a23e4617..4c7aae7433 100644 --- a/tools/js2dart/src/dart_writer.js +++ b/tools/transpiler/src/dart_writer.js @@ -228,7 +228,7 @@ export class DartTreeWriter extends JavaScriptParseTreeWriter { if (tree.name.identifierToken) { var nameValue = tree.name.identifierToken.value; if (nameValue === nameValue.toUpperCase()) { - // control annotations for js2dart + // control annotations for transpiler return; } } diff --git a/tools/js2dart/src/parser.js b/tools/transpiler/src/parser.js similarity index 100% rename from tools/js2dart/src/parser.js rename to tools/transpiler/src/parser.js