Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
625 changes: 392 additions & 233 deletions escodegen.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions test/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'use strict';

var fs = require('fs'),
esprima = require('./3rdparty/esprima-harmony.original'),
esprima = require('esprima'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect;
Expand All @@ -41,7 +41,8 @@ function test(code, expected) {
range: true,
loc: false,
tokens: true,
raw: false
raw: false,
sourceType: 'module'
};

tree = esprima.parse(code, options);
Expand Down
12 changes: 12 additions & 0 deletions test/comment/array-elements.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = [
/**
* Test 2
*/
a,
/*
* Test 1
*/
2,
// Test 3
3 + 3
];
12 changes: 12 additions & 0 deletions test/comment/array-elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var test = [
/**
* Test 2
*/
a,
/*
* Test 1
*/
2,
// Test 3
3+3
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function foo() {
return (
// comment
3 + 3
);
}
function foo() {
return (
// comment
3 + 3
);
}
function foo() {
return (
/* comment */
3 + 3
);
}
function foo() {
return (
/* comment
comment
comment
*/
3 + 3
);
}
function foo() {
return (
/* comment
comment
comment
*/
3 + 3
);
}
function foo() {
return (
// comment
/* comment */
// comment
3 + 3
);
}
function foo() {
return (
// one
3 + 3 - // two
(1 + 1)
);
}
function foo(a, b, c) {
return (
// comment
a >= b && a <= c || a === 42 || a === 666
);
}
function foo(a, b, c) {
return (
// comment
a >= b && a <= c || a === 42 || a === 666
);
}
function foo(a, b, c) {
throw (
// comment
a >= b && a <= c || a === 42 || a === 666
);
}
let arrowFn = () => (
// comment
{
a: 1,
b: 2
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// this test should pass, but it is not passing due to a bug
// https://github.com/estools/escodegen/issues/433

function foo() {
return /* comment */ (
// comment
3 + 3
);
}
91 changes: 91 additions & 0 deletions test/comment/comment-as-first-element-in-parenthesis-expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
function foo() {
return (
// comment
3+3
);
}

function foo() {
return ( // comment
3+3
);
}

function foo() {
return ( /* comment */
3+3
);
}

function foo() {
return ( /* comment
comment
comment
*/
3+3
);
}

function foo() {
return (
/* comment
comment
comment
*/
3+3
);
}

function foo() {
return (
// comment
/* comment */
// comment
3+3
);
}

function foo() {
return (
(
// one
3+3
) -
(
// two
1+1
)
);
}

function foo(a, b, c) {
return (
// comment
(a >= b && a <= c)
|| a === 42 || a === 666
);
}

function foo(a, b, c) {
return (
( // comment
a >= b &&
a <= c)
|| a === 42 || a === 666
);
}

function foo(a, b, c) {
throw (
// comment
(a >= b && a <= c)
|| a === 42 || a === 666
);
}

let arrowFn = () => (
// comment
{
a: 1, b: 2
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// this test should pass, but it is not passing due to a bug
// https://github.com/estools/escodegen/issues/433

function foo() {
return /* comment */ (
// comment
3+3
);
}
11 changes: 11 additions & 0 deletions test/comment/imports.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// this import is important
import 'foo';
import { foo } from 'foo';
import { foo as bar } from 'foo';
// this import is important too
import {
foo as bar,
// alias needed because of ...
test as testing,
logging
} from 'foo';
11 changes: 11 additions & 0 deletions test/comment/imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// this import is important
import 'foo';
import {foo} from 'foo';
import {foo as bar} from 'foo';
// this import is important too
import {
foo as bar,
// alias needed because of ...
test as testing,
logging
} from 'foo';
15 changes: 15 additions & 0 deletions test/comment/method-description.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class MyClass {
/**
* description
*/
foo(a, b) {
a.bar(b);
}
}
class MyClass2 {
// description
foo(a, b, c, // NOTE: ...
d = false) {
return 42;
}
}
17 changes: 17 additions & 0 deletions test/comment/method-description.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class MyClass {
/**
* description
*/
foo(a, b) {
a.bar(b);
}
}

class MyClass2 {
// description
foo(a, b, c,
// NOTE: ...
d = false) {
return 42;
}
}
6 changes: 4 additions & 2 deletions test/comment/try-block-line-comment.expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ finally {
}
try {
} catch (e) {
} finally {
} //
finally {
}
{
try {
} catch (e) {
} finally {
} //
finally {
}
}
27 changes: 27 additions & 0 deletions test/comment/variable-declaration.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let variable = // comment
3 + 3;
let variable = // comment
3 + 3;
let variable = /* comment */
3 + 3;
let variable = /* comment
comment
comment
*/
3 + 3;
let variable = // comment
/* comment */
// comment
3 + 3;
let variable = /* comment */
// comment
3 + 3;
let variable = // one
3 + 3 - // two
(1 + 1);
let age = // comment
42,
// comment
height = 165;
let variable = // comment
a >= b && a <= c || a === 42 || a === 666;
47 changes: 47 additions & 0 deletions test/comment/variable-declaration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
let variable =
// comment
3+3;

let variable = // comment
3+3;

let variable = /* comment */
3+3;

let variable = /* comment
comment
comment
*/
3+3;

let variable =
// comment
/* comment */
// comment
3+3;

let variable = /* comment */
// comment
3+3;

let variable =
(
// one
3+3
) -
(
// two
1+1
);

let age = // comment
42,
// comment
height = 165;

let variable = (
( // comment
a >= b &&
a <= c)
|| a === 42 || a === 666
);
2 changes: 2 additions & 0 deletions test/comment/variable-declaration.js.expected.todo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TOOD: https://github.com/estools/escodegen/issues/435
// the existing non-todo test expectation shall be adjusted accordingly once the issue is resolved