jashkenas--coffeescript/test/test.html

122 lines
2.4 KiB
HTML
Raw Normal View History

2010-10-11 18:22:01 -04:00
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>CoffeeScript Test Suite</title>
<script src="../extras/coffee-script.js"></script>
<style>
body {
margin: 30px;
font-family: Menlo, Monaco, monospace;
}
h1 {
font-size: 20px;
}
#stdout {
}
</style>
</head>
<body>
<h1>CoffeeScript Test Suite</h1>
<pre id="stdout"></pre>
<script type="text/coffeescript">
stdout = document.getElementById 'stdout'
start = new Date
success = total = done = failed = 0
2011-05-01 08:28:00 -04:00
say = (msg) ->
2010-10-11 18:22:01 -04:00
div = document.createElement 'div'
div.appendChild document.createTextNode msg
stdout.appendChild div
msg
@test = (desc, fn) ->
2010-12-12 21:41:04 -05:00
fn()
@ok = (good, msg) ->
2010-10-11 18:22:01 -04:00
++total
if good then ++success else throw Error say msg
@eq = (x, y, msg) -> ok x is y, msg ? x + ' !== ' + y
2010-10-11 18:22:01 -04:00
arrayEqual = (a, b) ->
if a is b
# 0 isnt -0
a isnt 0 or 1/a is 1/b
else if a instanceof Array and b instanceof Array
return no unless a.length is b.length
return no for el, idx in a when not arrayEq el, b[idx]
yes
else
# NaN is NaN
a isnt a and b isnt b
@doesNotThrow = (fn) ->
2010-12-22 20:10:21 -05:00
fn()
ok true
@arrayEq = (a, b, msg) -> ok arrayEqual(a,b), msg
@throws = (fun, err, msg) ->
2010-12-24 14:02:10 -05:00
try
fun()
catch e
if err
eq e, err
else
ok yes
return
ok no
2010-10-11 18:22:01 -04:00
run = (name) ->
2011-05-01 08:28:00 -04:00
CoffeeScript.load "#{name}.coffee", ->
say '\u2714 ' + name
2010-10-11 18:22:01 -04:00
fin() if ++done is names.length
fin = ->
yay = success is total and not failed
sec = (new Date - start) / 1000
msg = "passed #{success} tests in #{ sec.toFixed 2 } seconds"
msg = "failed #{ total - success } tests and #{msg}" unless yay
say msg, yay
run name for name in names = [
2011-05-01 08:28:00 -04:00
'arrays'
2010-10-11 18:22:01 -04:00
'assignment'
2011-05-01 08:28:00 -04:00
'booleans'
'classes'
'cluster'
2010-10-11 18:22:01 -04:00
'comments'
'compilation'
'comprehensions'
'control_flow'
2010-12-12 21:41:04 -05:00
'exception_handling'
'formatting'
'function_invocation'
2011-05-01 08:28:00 -04:00
'functions'
'helpers'
'importing'
'interpolation'
'javascript_literals'
Support import and export of ES2015 modules (#4300) This pull request adds support for ES2015 modules, by recognizing `import` and `export` statements. The following syntaxes are supported, based on the MDN [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) and [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) pages: ```js import "module-name" import defaultMember from "module-name" import * as name from "module-name" import { } from "module-name" import { member } from "module-name" import { member as alias } from "module-name" import { member1, member2 as alias2, … } from "module-name" import defaultMember, * as name from "module-name" import defaultMember, { … } from "module-name" export default expression export class name export { } export { name } export { name as exportedName } export { name as default } export { name1, name2 as exportedName2, name3 as default, … } export * from "module-name" export { … } from "module-name" ``` As a subsitute for ECMAScript’s `export var name = …` and `export function name {}`, CoffeeScript also supports: ```js export name = … ``` CoffeeScript also supports optional commas within `{ … }`. This PR converts the supported `import` and `export` statements into ES2015 `import` and `export` statements; it **does not resolve the modules**. So any CoffeeScript with `import` or `export` statements will be output as ES2015, and will need to be transpiled by another tool such as Babel before it can be used in a browser. We will need to add a warning to the documentation explaining this. This should be fully backwards-compatible, as `import` and `export` were previously reserved keywords. No flags are used. There are extensive tests included, though because no current JavaScript runtime supports `import` or `export`, the tests compare strings of what the compiled CoffeeScript output is against what the expected ES2015 should be. I also conducted two more elaborate tests: * I forked the [ember-piqu](https://github.com/pauc/piqu-ember) project, which was an Ember CLI app that used ember-cli-coffeescript and [ember-cli-coffees6](https://github.com/alexspeller/ember-cli-coffees6) (which adds “support” for `import`/`export` by wrapping such statements in backticks before passing the result to the CoffeeScript compiler). I removed `ember-cli-coffees6` and replaced the CoffeeScript compiler used in the build chain with this code, and the app built without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-piqu) * I also forked the [CoffeeScript version of Meteor’s Todos example app](https://github.com/meteor/todos/tree/coffeescript), and replaced all of its `require` statements with the `import` and `export` statements from the original ES2015 version of the app on its `master` branch. I then updated the `coffeescript` Meteor package in the app to use this new code, and again the app builds without errors. [Demo here.](https://github.com/GeoffreyBooth/coffeescript-modules-test-meteor-todos) The discussion history for this work started [here](https://github.com/jashkenas/coffeescript/pull/4160) and continued [here](https://github.com/GeoffreyBooth/coffeescript/pull/2). @lydell provided guidance, and @JimPanic and @rattrayalex contributed essential code.
2016-09-14 14:46:05 -04:00
'modules'
2011-05-01 08:28:00 -04:00
'numbers'
'objects'
2010-12-12 21:41:04 -05:00
'operators'
'option_parser'
2011-05-01 08:28:00 -04:00
'ranges'
'regexps'
'scope'
'slicing_and_splicing'
'soaks'
2011-05-01 08:28:00 -04:00
'strings'
2010-10-11 18:22:01 -04:00
]
2013-03-20 04:39:36 -04:00
# allow utf-8 chars in comments
# 智に働けば角が立つ、情に掉させば流される。
2010-10-11 18:22:01 -04:00
</script>
</body>
</html>