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

Partially import melody project into core #33

Merged
merged 28 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
04a4787
Initial Commit
Oct 18, 2017
bf2c0d8
Chore - Setup travis (#1)
efegurkan Oct 25, 2017
cab4830
test: melody code frame (#16)
ayusharma Jan 6, 2018
1fd4d98
fix: adds missing constant type (#21)
ayusharma Jan 12, 2018
c6ba301
Fix not in operator (#26)
timdegroote Feb 1, 2018
be70068
Fixed Typo in call to date filter (#35)
iandevlin Apr 3, 2018
512d11d
fix: generates esm modules using rollup (#42)
ayusharma Aug 15, 2018
8f4de03
fix: incorrect `is` method call in melody-types (#20) (#52)
ayusharma Aug 21, 2018
2166450
Add implementation for filter 'trim' to be compatible with Twig (#64)
taueres Sep 18, 2018
927c739
Add initial draft of async mounting (#82)
pago Jan 11, 2019
880a5fc
Warn about usage of non-breaking space (#107)
byara Apr 23, 2019
de6ed9f
Add twig comment ast node type (#135)
twbartel Nov 4, 2019
e503ed2
Preserve HTML comments (#137)
twbartel Nov 4, 2019
59cde7f
Add option to decode entities (#136)
twbartel Nov 4, 2019
2eaac1e
Optionally skip whitespace trimming in tokenizer (#139)
twbartel Nov 11, 2019
dc8b7d1
Tokenizer preserve whitespace (#140)
twbartel Nov 20, 2019
e3f7640
Mark BinaryConcatExpressions generated by Melody (#141)
twbartel Nov 22, 2019
84fd423
Fix typo bug in Parser option
twbartel Nov 26, 2019
657a7a3
Make Lexer interrupt text token when hitting an HTML comment (#145)
twbartel Dec 16, 2019
8f26f1f
Twig tags: Preserve information on whitespace control (#147)
twbartel Dec 17, 2019
2f32c2d
Add parsing of declarations like <!DOCTYPE html> (#150)
twbartel Jan 8, 2020
0c504be
Parser: More precise location information (#148)
twbartel Jan 8, 2020
673aac6
Add missing trim properties on PrintExpressionStatement (#152)
twbartel Jan 9, 2020
e636dcb
Bugfix: Prevent Number tokens from ending in a dot "." (#153)
twbartel Jan 10, 2020
1969579
Bugfix: Preserve backslashes in string literals (#149)
twbartel Jan 11, 2020
d0f4e7a
Introduce generic twig tags (#154)
twbartel Feb 27, 2020
af7a067
Retain trimming information for conditional expressions (#162)
May 29, 2020
0d9e2aa
chore(dependency): partially import melody project
zackad Jul 18, 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
44 changes: 44 additions & 0 deletions src/melody/melody-code-frame/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright 2017 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import lineNumbers from './lineNumbers';

Check failure on line 16 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'./lineNumbers'` with `"./lineNumbers"`

Check failure on line 16 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'./lineNumbers'` with `"./lineNumbers"`
import { repeat } from 'lodash';

Check failure on line 17 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

'lodash' should be listed in the project's dependencies. Run 'npm i -S lodash' to add it

Check failure on line 17 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'lodash'` with `"lodash"`

Check failure on line 17 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

'lodash' should be listed in the project's dependencies. Run 'npm i -S lodash' to add it

Check failure on line 17 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'lodash'` with `"lodash"`

const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;

export default function({ rawLines, lineNumber, colNumber, length }) {

Check failure on line 21 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Insert `·`

Check failure on line 21 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Insert `·`
const lines = rawLines.split(NEWLINE),

Check failure on line 22 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Split 'const' declarations into multiple statements

Check failure on line 22 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Split 'const' declarations into multiple statements
start = Math.max(lineNumber - 3, 0),
end = Math.min(lineNumber + 3, lines.length);

return lineNumbers(lines.slice(start, end), {
start: start + 1,
before: ' ',

Check failure on line 28 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'··'` with `"··"`

Check failure on line 28 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'··'` with `"··"`
after: ' | ',

Check failure on line 29 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'·|·'` with `"·|·"`

Check failure on line 29 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'·|·'` with `"·|·"`
transform(params) {
if (params.number !== lineNumber) {
return;
}

if (typeof colNumber === 'number') {

Check failure on line 35 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'number'` with `"number"`

Check failure on line 35 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'number'` with `"number"`
params.line += `\n${params.before}${repeat(' ', params.width)}${

Check failure on line 36 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'·'` with `"·"`

Check failure on line 36 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'·'` with `"·"`
params.after
}${repeat(' ', colNumber)}${repeat('^', length)}`;

Check failure on line 38 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (18)

Replace `'·',·colNumber)}${repeat('^'` with `"·",·colNumber)}${repeat("^"`

Check failure on line 38 in src/melody/melody-code-frame/index.js

View workflow job for this annotation

GitHub Actions / Test (20)

Replace `'·',·colNumber)}${repeat('^'` with `"·",·colNumber)}${repeat("^"`
}

params.before = params.before.replace(/^./, '>');
},
}).join('\n');
}
45 changes: 45 additions & 0 deletions src/melody/melody-code-frame/lineNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2014, 2015 Simon Lydell
// X11 (“MIT”) Licensed. (See LICENSE.)
/**
* Copyright 2017 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { padStart } from 'lodash';

const get = options => (key, defaultValue) =>
key in options ? options[key] : defaultValue;

function lineNumbers(lines, options) {
const getOption = get(options);
const transform = getOption('transform', Function.prototype);
const padding = getOption('padding', ' ');
const before = getOption('before', ' ');
const after = getOption('after', ' | ');
const start = getOption('start', 1);
const end = start + lines.length - 1;
const width = String(end).length;
return lines.map(function(line, index) {
const number = start + index;
const params = { before, number, width, after, line };
transform(params);
return (
params.before +
padStart(params.number, width, padding) +
params.after +
params.line
);
});
}

export default lineNumbers;
167 changes: 167 additions & 0 deletions src/melody/melody-extension-core/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**
* Copyright 2017 trivago N.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { unaryOperators, binaryOperators, tests } from './operators';
import { AutoescapeParser } from './parser/autoescape';
import { BlockParser } from './parser/block';
import { DoParser } from './parser/do';
import { EmbedParser } from './parser/embed';
import { ExtendsParser } from './parser/extends';
import { FilterParser } from './parser/filter';
import { FlushParser } from './parser/flush';
import { ForParser } from './parser/for';
import { FromParser } from './parser/from';
import { IfParser } from './parser/if';
import { ImportParser } from './parser/import';
import { IncludeParser } from './parser/include';
import { MacroParser } from './parser/macro';
import { SetParser } from './parser/set';
import { SpacelessParser } from './parser/spaceless';
import { UseParser } from './parser/use';
import { MountParser } from './parser/mount';

import forVisitor from './visitors/for';
import testVisitor from './visitors/tests';
import filters from './visitors/filters';
import functions from './visitors/functions';

const filterMap = [
'attrs',
'classes',
'styles',
'batch',
'escape',
'format',
'merge',
'nl2br',
'number_format',
'raw',
'replace',
'reverse',
'round',
'striptags',
'title',
'url_encode',
'trim',
].reduce((map, filterName) => {
map[filterName] = 'melody-runtime';
return map;
}, Object.create(null));

Object.assign(filterMap, filters);

const functionMap = [
'attribute',
'constant',
'cycle',
'date',
'max',
'min',
'random',
'range',
'source',
'template_from_string',
].reduce((map, functionName) => {
map[functionName] = 'melody-runtime';
return map;
}, Object.create(null));
Object.assign(functionMap, functions);

export const extension = {
tags: [
AutoescapeParser,
BlockParser,
DoParser,
EmbedParser,
ExtendsParser,
FilterParser,
FlushParser,
ForParser,
FromParser,
IfParser,
ImportParser,
IncludeParser,
MacroParser,
SetParser,
SpacelessParser,
UseParser,
MountParser,
],
unaryOperators,
binaryOperators,
tests,
visitors: [forVisitor, testVisitor],
filterMap,
functionMap,
};

export {
AutoescapeBlock,
BlockStatement,
BlockCallExpression,
MountStatement,
DoStatement,
EmbedStatement,
ExtendsStatement,
FilterBlockStatement,
FlushStatement,
ForStatement,
ImportDeclaration,
FromStatement,
IfStatement,
IncludeStatement,
MacroDeclarationStatement,
VariableDeclarationStatement,
SetStatement,
SpacelessBlock,
AliasExpression,
UseStatement,
UnaryNotExpression,
UnaryNeqExpression,
UnaryPosExpression,
BinaryOrExpression,
BinaryAndExpression,
BitwiseOrExpression,
BitwiseXorExpression,
BitwiseAndExpression,
BinaryEqualsExpression,
BinaryNotEqualsExpression,
BinaryLessThanExpression,
BinaryGreaterThanExpression,
BinaryLessThanOrEqualExpression,
BinaryGreaterThanOrEqualExpression,
BinaryNotInExpression,
BinaryInExpression,
BinaryMatchesExpression,
BinaryStartsWithExpression,
BinaryEndsWithExpression,
BinaryRangeExpression,
BinaryAddExpression,
BinaryMulExpression,
BinaryDivExpression,
BinaryFloorDivExpression,
BinaryModExpression,
BinaryPowerExpression,
BinaryNullCoalesceExpression,
TestEvenExpression,
TestOddExpression,
TestDefinedExpression,
TestSameAsExpression,
TestNullExpression,
TestDivisibleByExpression,
TestConstantExpression,
TestEmptyExpression,
TestIterableExpression,
} from './types';
Loading