Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/chai upgrade #1711

Draft
wants to merge 40 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
312ea41
🔁❄️🧩: add support for import maps
merryman Aug 9, 2024
0f68699
🔁❄️: add sourcemap support for bundler
merryman Oct 2, 2024
c344735
❄️🪨🔁☕️: support esm:// syntax in import maps
merryman Dec 9, 2024
0812df4
🔁: fix linting for source transform capture code
merryman Oct 4, 2024
a0c45a4
🔁: fix destructuring transform so destructured obj returned
merryman Feb 6, 2025
da8d444
🧩: fix esm regex to be more accurate
merryman Dec 5, 2024
3194b89
🧩: curb module updates if exportConflicts are present
merryman Dec 5, 2024
d4fbc11
🧩: fix esm module url resolution
merryman Dec 10, 2024
4c5e6b2
🌳: fix statementOf()
merryman Oct 2, 2024
28cbe03
🌳: support async param for nodes.funcExpr
merryman Dec 5, 2024
008aa25
🌳: consider if statement blocks as separate scopes
merryman Dec 9, 2024
5d954c3
🌳: consider for loops as separate scopes
merryman Feb 6, 2025
e03d54e
🫓: rebuild flatn
merryman Feb 6, 2025
e54550e
🔁: add babel module transform
merryman Dec 5, 2024
e4b0384
🔁: add babel dependencies
merryman Dec 5, 2024
4cd12bf
🔁: add babel tests and make tests formatting independent
merryman Dec 5, 2024
876b3de
🔁: merge babel transform visitor for improved performance
merryman Dec 5, 2024
d3268ae
🔁: silence dynamic import warning in babel
merryman Dec 18, 2024
c556a61
🔁: remove dead code and fix formatting in babel plugin
merryman Dec 20, 2024
952ac53
🔁: merge more visitors to improve performance
merryman Dec 20, 2024
8423986
🔁: fix destructuring assignment transform bug
merryman Dec 19, 2024
ab99aa4
🧑‍🏫: add support for class transform to work with babel
merryman Dec 5, 2024
6c0c289
🧑‍🏫: add default acorn nodes to class transform, adjust tests
merryman Dec 5, 2024
f47c508
🧑‍🏫: adjust class transform in test
merryman Dec 14, 2024
2469fab
❄️: bump rollup
merryman Dec 5, 2024
52d6fad
❄️: fix bundling issue with babel modules
merryman Dec 5, 2024
9cdf1d3
❄️🧩🖥️: integrate babel transpiler
merryman Dec 5, 2024
a2d3540
🧩: fix storing source maps in local storage
merryman Dec 16, 2024
76e8e35
🧩: fix module tests
merryman Dec 14, 2024
b3bbf76
📦🧩🔁: switch to babel transpiler in server side
merryman Dec 18, 2024
2dbdbdc
🎨❄️🧩: remove systemjs-init related stuff that is no longer needed
merryman Dec 18, 2024
672a2ef
🧩🖥️: remove lively.transpiler references that are no longer needed
merryman Dec 18, 2024
c9263d5
📙🖥️: fix some test issues
merryman Dec 16, 2024
a658969
🧩: avoid issues with json files in freezer bundles
merryman Dec 5, 2024
2c0c30a
📦: add format meta for packages-config
merryman Dec 11, 2024
33c7652
☕️: bump chai and mocha
merryman Dec 5, 2024
baa48a8
🌳🧑‍🏫🧩🎨📇: replace deep prop check with nested
merryman Dec 14, 2024
7ae0be2
🧩: use fuzzy parse to check for mocha test
merryman Dec 16, 2024
936bd22
🎨: adjust spec comparison
merryman Dec 14, 2024
180c15a
🎨: adjust render tests to work in non p3 envs
merryman Dec 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions flatn/flatn-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15493,7 +15493,7 @@ const requestMap = {};

class ESMResource extends Resource {
static normalize (esmUrl) {
const id = esmUrl.replaceAll(/esm:\/\/(run|cache)\//g, '');
const id = esmUrl.replaceAll(/esm:\/\/([^\/]*)\//g, '');

let pathStructure = id.split('/').filter(Boolean);

Expand All @@ -15511,7 +15511,6 @@ class ESMResource extends Resource {
pathStructure.push(fileName);
}


if (pathStructure[pathStructure.length - 1].endsWith('+esm')) {
pathStructure[pathStructure.length - 1] = pathStructure[pathStructure.length - 1].replace('+esm', 'esm.js');
}
Expand All @@ -15527,13 +15526,22 @@ class ESMResource extends Resource {
return pathStructure;
}

async read () {
let module;

const id = this.url.replace(/esm:\/\/(run|cache)\//g, '');
let baseUrl = 'https://jspm.dev/';
getEsmURL () {
let baseUrl;
if (this.url.startsWith('esm://run/npm/')) baseUrl = 'https://cdn.jsdelivr.net/';
else if (this.url.startsWith('esm://run/')) baseUrl = 'https://esm.run/';
else if (this.url.startsWith('esm://cache/')) baseUrl = 'https://jspm.dev/';
else {
const domain = this.url.match(/esm:\/\/([^\/]*)\//)?.[1];
baseUrl = `https://${domain}/`;
}
return baseUrl;
}

async read () {
let module;
const id = this.url.replace(/esm:\/\/([^\/]*)\//g, '');
const esmURL = this.getEsmURL();

let pathStructure = ESMResource.normalize(id);

Expand All @@ -15544,7 +15552,7 @@ class ESMResource extends Resource {
if (typeof lively !== 'undefined' && (hit = lively.memory_esm?.get(shortName))) return await hit.blob.text();
module = await res.read();
} else {
module = await resource((baseUrl + id)).read();
module = await resource((esmURL + id)).read();
res.write(module);
}
return module;
Expand Down Expand Up @@ -15627,7 +15635,9 @@ class ESMResource extends Resource {
}

async exists () {
// stub that needs to exist
const id = this.url.replace(/esm:\/\/([^\/]*)\//g, '');
const baseUrl = this.getEsmURL();
return await resource(baseUrl).join(id).exists();
}

async remove () {
Expand Down
46 changes: 46 additions & 0 deletions lively.ast/lib/mozilla-ast-visitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,52 @@ class ScopeVisitor extends Visitor {
return node;
}

visitForStatement (node, scope, path) {
const visitor = this;
// init is of types VariableDeclaration, Expression
if (node.init) {
node.init = visitor.accept(node.init, scope, path.concat(['init']));
}
// test is of types Expression
if (node.test) {
node.test = visitor.accept(node.test, scope, path.concat(['test']));
}
// update is of types Expression
if (node.update) {
node.update = visitor.accept(node.update, scope, path.concat(['update']));
}
// body is of types Statement
node.body = visitor.accept(node.body, this.newScope(node, scope), path.concat(['body']));
return node;
}

visitForInStatement (node, scope, path) {
const visitor = this;
// left is of types VariableDeclaration, Pattern
node.left = visitor.accept(node.left, scope, path.concat(['left']));
// right is of types Expression
node.right = visitor.accept(node.right, scope, path.concat(['right']));
// body is of types Statement
node.body = visitor.accept(node.body, this.newScope(node, scope), path.concat(['body']));
return node;
}

visitIfStatement (node, scope, path) {
const visitor = this;

node.test = visitor.accept(node.test, scope, path.concat(['test']));

const consequentScope = this.newScope(node, scope);
node.consequent = visitor.accept(node.consequent, consequentScope, path.concat(['consequent']));

if (node.alternate) {
const alternateScope = this.newScope(node, scope);
node.alternate = visitor.accept(node.alternate, alternateScope, path.concat(['alternate']));
}

return node;
}

visitLabeledStatement (node, scope, path) {
const visitor = this;
// ignore label
Expand Down
5 changes: 3 additions & 2 deletions lively.ast/lib/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function binaryExpr (left, op, right) {
};
}

function funcExpr ({ arrow, id: funcId, expression, generator }, params = [], ...statements) {
function funcExpr ({ arrow, id: funcId, expression, generator, isAsync }, params = [], ...statements) {
// lively.ast.stringify(funcExpr({id: "foo"}, ["a"], exprStmt(id("3"))))
// // => "function foo(a) { 3; }"
params = params.map(ea => typeof ea === 'string' ? id(ea) : ea);
Expand All @@ -44,7 +44,8 @@ function funcExpr ({ arrow, id: funcId, expression, generator }, params = [], ..
? statements[0]
: { body: statements, type: 'BlockStatement' },
expression: expression || false,
generator: generator || false
generator: generator || false,
async: isAsync
};
}

Expand Down
2 changes: 1 addition & 1 deletion lively.ast/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ function statementOf (parsed, node, options) {
// Find the statement that a target node is in. Example:
// let source be "var x = 1; x + 1;" and we are looking for the
// Identifier "x" in "x+1;". The second statement is what will be found.
const nodes = nodesAt(node.start, parsed);
const nodes = nodesAt(node.start + 1, parsed);
const found = nodes.reverse().find(node => _stmtTypes.includes(node.type));
if (options && options.asPath) {
const v = new BaseVisitor(); let foundPath;
Expand Down
20 changes: 9 additions & 11 deletions lively.ast/tests/es6-test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/*global process, require, beforeEach, afterEach, describe, it*/
/* global process, require, beforeEach, afterEach, describe, it */

import { expect } from "mocha-es6";
import { expect } from 'mocha-es6';

import { parse } from "../lib/parser.js";
import { parse } from '../lib/parser.js';

describe('es6', function() {

it("arrow function", function() {
var code = '() => 23;'
var parsed = parse(code);
expect(parsed).deep.property("body[0].expression.type")
.equals("ArrowFunctionExpression");
describe('es6', function () {
it('arrow function', function () {
let code = '() => 23;';
let parsed = parse(code);
expect(parsed).has.nested.property('body[0].expression.type')
.equals('ArrowFunctionExpression');
});

});
69 changes: 32 additions & 37 deletions lively.ast/tests/parser-test.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,48 @@
/*global beforeEach, afterEach, describe, it*/
/* global beforeEach, afterEach, describe, it */

import { expect } from "mocha-es6";
import { expect } from 'mocha-es6';

import { printAst } from "../lib/mozilla-ast-visitor-interface.js";
import { parse, parseFunction } from "../lib/parser.js";

describe('parse', function() {
import { printAst } from '../lib/mozilla-ast-visitor-interface.js';
import { parse, parseFunction } from '../lib/parser.js';

describe('parse', function () {
it('JavaScript code', () =>
expect(parse("1 + 2"))
.deep.property("body[0].type")
.equals("ExpressionStatement"));

describe("async / await", () => {

it("parses nested awaits", () => {
var src = "await (await foo()).bar()",
parsed = parse(src),
expected = ":Program(0-25)\n"
+ "\\-.body[0]:ExpressionStatement(0-25)\n"
+ " \\-.body[0].expression:AwaitExpression(0-25)\n"
+ " \\-.body[0].expression.argument:CallExpression(6-25)\n"
+ " \\-.body[0].expression.argument.callee:MemberExpression(6-23)\n"
+ " |-.body[0].expression.argument.callee.object:AwaitExpression(7-18)\n"
+ " | \\-.body[0].expression.argument.callee.object.argument:CallExpression(13-18)\n"
+ " | \\-.body[0].expression.argument.callee.object.argument.callee:Identifier(13-16)\n"
+ " \\-.body[0].expression.argument.callee.property:Identifier(20-23)"
expect(printAst(parsed, {printPositions: true})).to.equal(expected);
expect(parse('1 + 2'))
.nested.property('body[0].type')
.equals('ExpressionStatement'));

describe('async / await', () => {
it('parses nested awaits', () => {
let src = 'await (await foo()).bar()';
let parsed = parse(src);
let expected = ':Program(0-25)\n' +
'\\-.body[0]:ExpressionStatement(0-25)\n' +
' \\-.body[0].expression:AwaitExpression(0-25)\n' +
' \\-.body[0].expression.argument:CallExpression(6-25)\n' +
' \\-.body[0].expression.argument.callee:MemberExpression(6-23)\n' +
' |-.body[0].expression.argument.callee.object:AwaitExpression(7-18)\n' +
' | \\-.body[0].expression.argument.callee.object.argument:CallExpression(13-18)\n' +
' | \\-.body[0].expression.argument.callee.object.argument.callee:Identifier(13-16)\n' +
' \\-.body[0].expression.argument.callee.property:Identifier(20-23)';
expect(printAst(parsed, { printPositions: true })).to.equal(expected);
});

});

describe("parseFunction", () => {

it("anonmyous function", () => {
expect(parseFunction("function(x) { return x + 1; }").type).equals("FunctionExpression")
describe('parseFunction', () => {
it('anonmyous function', () => {
expect(parseFunction('function(x) { return x + 1; }').type).equals('FunctionExpression');
});

it("named function", () => {
expect(parseFunction("function foo(x) { return x + 1; }")).containSubset({type: "FunctionExpression", id: {name: "foo"}})
it('named function', () => {
expect(parseFunction('function foo(x) { return x + 1; }')).containSubset({ type: 'FunctionExpression', id: { name: 'foo' } });
});

it("arrow function", () => {
expect(parseFunction("(x) => { return x + 1; }")).containSubset({type: "ArrowFunctionExpression"})
it('arrow function', () => {
expect(parseFunction('(x) => { return x + 1; }')).containSubset({ type: 'ArrowFunctionExpression' });
});

it("short function", () => {
expect(parseFunction("x => x + 1")).containSubset({type: "ArrowFunctionExpression"})
it('short function', () => {
expect(parseFunction('x => x + 1')).containSubset({ type: 'ArrowFunctionExpression' });
});

});
});
Loading
Loading