Skip to content

Commit

Permalink
only pick up first comment at top of expression for alias
Browse files Browse the repository at this point in the history
  • Loading branch information
sc1f committed Nov 1, 2021
1 parent e6fc89a commit 55f5db7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ export default function (Module) {
// First, look for a column alias, which is a // style comment
// on the first line of the expression.
let expression_alias;
let alias_match = expression_string.match(/^\/\/(?<alias>.+?)$/m);
let alias_match = expression_string.match(/^\/\/(?<alias>.+?)\n/);

if (alias_match?.groups?.alias) {
expression_alias = alias_match.groups.alias.trim();
Expand Down
15 changes: 10 additions & 5 deletions packages/perspective/test/js/expressions/functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -1210,15 +1210,20 @@ module.exports = (perspective) => {
const table = await perspective.table({a: [1, 2, 3]});
const view = await table.view({
expressions: [
`// abc
var x := 1 + 2; // another comment
x + 3 + 4 # comment`,
"var x := 1 + 2;\n// another comment\nx + 3 + 4 # comment",
],
});
const schema = await view.expression_schema();
expect(schema).toEqual({abc: "float"});
expect(schema).toEqual({
"var x := 1 + 2;\n// another comment\nx + 3 + 4 # comment":
"float",
});
const result = await view.to_columns();
expect(result["abc"]).toEqual(Array(3).fill(10));
expect(
result[
"var x := 1 + 2;\n// another comment\nx + 3 + 4 # comment"
]
).toEqual(Array(3).fill(10));
await view.delete();
await table.delete();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,10 +1673,10 @@ def test_view_string_expression(self):

def test_view_expession_multicomment(self):
table = Table({"a": [1, 2, 3, 4]})
view = table.view(expressions=["//abc\nvar x := 1 + 2; // def\nx + 100 // cdefghijk"])
assert view.expression_schema() == {"abc": float}
view = table.view(expressions=["var x := 1 + 2;\n// def\nx + 100 // cdefghijk"])
assert view.expression_schema() == {"var x := 1 + 2;\n// def\nx + 100 // cdefghijk": float}
assert view.to_columns() == {
"abc": [103, 103, 103, 103],
"var x := 1 + 2;\n// def\nx + 100 // cdefghijk": [103, 103, 103, 103],
"a": [1, 2, 3, 4]
}

Expand Down

0 comments on commit 55f5db7

Please sign in to comment.