Skip to content

Commit

Permalink
new build system
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Oct 12, 2018
1 parent e7b44d4 commit feabb47
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
node_modules
lib
dist
test.mjs
.eslintcache
19 changes: 19 additions & 0 deletions LICENSE
@@ -0,0 +1,19 @@
Copyright (c) 2018 engine262 Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
9 changes: 0 additions & 9 deletions LICENSE.md

This file was deleted.

11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -2,12 +2,11 @@
"name": "engine262",
"version": "0.0.1",
"description": "Implementation of ECMA-262 in JavaScript",
"main": "lib/api.mjs",
"main": "dist/engine262",
"dependencies": {
"acorn": "^6.0.2"
},
"devDependencies": {
"@babel/cli": "^7.1.2",
"@babel/core": "^7.1.2",
"@babel/plugin-syntax-object-rest-spread": "^7.0.0",
"babel-eslint": "^10.0.1",
Expand All @@ -17,14 +16,16 @@
"eslint-plugin-jsx-a11y": "^6.1.1",
"eslint-plugin-react": "^7.10.0",
"glob": "^7.1.3",
"rollup": "^0.66.6",
"rollup-plugin-babel": "^4.0.3",
"source-map-support": "^0.5.9",
"yaml": "^1.0.0-rc.8"
},
"scripts": {
"test": "node --experimental-modules test/test262.mjs",
"lint": "eslint transform.js transform_do.js test/test262.mjs src/ --ext=js,mjs --cache",
"build": "babel src -d lib --keep-file-extension --source-maps --plugins=@babel/plugin-syntax-object-rest-spread,./transform.js",
"build-do": "babel src -d lib --keep-file-extension --source-maps --plugins=@babel/plugin-syntax-object-rest-spread,./transform_do.js"
"lint": "eslint transform.js transform_do.js build.js test/test262.mjs src/ --ext=js,mjs --cache",
"build": "rollup -c",
"build-do": "rollup -c --environment USE_DO_EXPRESSIONS"
},
"repository": {
"type": "git",
Expand Down
39 changes: 39 additions & 0 deletions rollup.config.js
@@ -0,0 +1,39 @@
'use strict';

const fs = require('fs');
const babel = require('rollup-plugin-babel');
const { name, version } = require('./package.json');

const banner = `/*
* engine262 ${version}
*
* ${fs.readFileSync('./LICENSE', 'utf8').trim().split('\n').join('\n * ')}
*/
`;

module.exports = () => ({
input: './src/api.mjs',
plugins: [
babel({
exclude: 'node_modules/**',
plugins: [
'@babel/plugin-syntax-object-rest-spread',
process.env.USE_DO_EXPRESSIONS ? './transform_do.js' : './transform.js',
],
}),
],
output: [
{
file: 'dist/engine262.js',
format: 'umd',
sourcemap: true,
name,
banner,
}, {
file: 'dist/engine262.mjs',
format: 'es',
sourcemap: true,
banner,
},
],
});
6 changes: 3 additions & 3 deletions src/api.mjs
Expand Up @@ -49,7 +49,7 @@ class APIRealm {
if (global.$262 && global.$262.handlePrint) {
global.$262.handlePrint(...args);
} else {
console.log(...args.map((a) => inspect(a))); // eslint-disable-line no-console
console.log(...args.map((a) => Inspect(a))); // eslint-disable-line no-console
}
return Value.undefined;
}, [], realm),
Expand Down Expand Up @@ -144,7 +144,7 @@ export {
APIObject as Object,
};

export function inspect(value, realm = surroundingAgent.currentRealmRecord, quote = true, indent = 0) {
export function Inspect(value, realm = surroundingAgent.currentRealmRecord, quote = true, indent = 0) {
const type = Type(value);
if (type === 'Undefined') {
return 'undefined';
Expand Down Expand Up @@ -181,7 +181,7 @@ export function inspect(value, realm = surroundingAgent.currentRealmRecord, quot
indent += 1;
for (const key of keys) {
const C = value.properties.get(key);
out = `${out}\n${' '.repeat(indent)}${inspect(key, realm, false, indent)}: ${inspect(C.Value, realm, false, indent)},`;
out = `${out}\n${' '.repeat(indent)}${Inspect(key, realm, false, indent)}: ${Inspect(C.Value, realm, false, indent)},`;
}
indent -= 1;
return `${out}\n${' '.repeat(indent)}${isArray ? ']' : '}'}`;
Expand Down
22 changes: 4 additions & 18 deletions src/completion.mjs
Expand Up @@ -94,14 +94,8 @@ export function UpdateEmpty(completionRecord, value) {
}

// #sec-returnifabrupt
export function ReturnIfAbrupt(argument) {
if (argument instanceof AbruptCompletion) {
return argument;
}
if (argument instanceof Completion) {
return argument.Value;
}
return argument;
export function ReturnIfAbrupt() {
throw new TypeError('ReturnIfAbrupt requires build');
}

// #sec-returnifabrupt-shorthands ? OperationName()
Expand All @@ -117,16 +111,8 @@ export function X(val) {
}

// #sec-ifabruptrejectpromise
export function IfAbruptRejectPromise(value, capability) {
if (value instanceof AbruptCompletion) {
const hygenicTemp = Call(capability.Reject, Value.undefined, [value.Value]);
if (hygenicTemp instanceof AbruptCompletion) {
return hygenicTemp;
}
return capability.Promise;
} else if (value instanceof Completion) {
value = value.Value;
}
export function IfAbruptRejectPromise() {
throw new TypeError('IfAbruptRejectPromise requires build');
}

export function EnsureCompletion(val) {
Expand Down
6 changes: 3 additions & 3 deletions test/test262.mjs
Expand Up @@ -11,8 +11,8 @@ import {
Abstract,
Completion,
AbruptCompletion,
inspect,
} from '../lib/api.mjs';
Inspect,
} from '..';

util.inspect.defaultOptions.depth = 2;

Expand Down Expand Up @@ -103,7 +103,7 @@ async function run({ source, meta, strict }) {
if (meta.negative) {
return { status: PASS };
} else {
return { status: FAIL, error: inspect(completion.Value, $262.realm.realm) };
return { status: FAIL, error: Inspect(completion.Value, $262.realm.realm) };
}
}

Expand Down

0 comments on commit feabb47

Please sign in to comment.