Skip to content

Commit

Permalink
fixes template tag indentations being applied
Browse files Browse the repository at this point in the history
  • Loading branch information
panoply committed Dec 25, 2022
1 parent eb7a7ec commit 74f5ae4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/prettify/src/beautify/script.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Options } from 'types/prettify';
import { prettify } from '@prettify/model';
import { create } from '@utils/native';
import { repeatChar } from '@utils/helpers';
import { NIL, NWL, WSP } from '@utils/chars';
import { StripEnd } from '@utils/regex';
Expand Down Expand Up @@ -96,7 +95,7 @@ prettify.beautify.script = (options: Options) => {
/**
* External indexes
*/
const externalIndex = create(null);
const externalIndex = {};

/**
* Reference to `options.parsed` which is the
Expand Down Expand Up @@ -225,7 +224,7 @@ prettify.beautify.script = (options: Options) => {

destructfix(false, false);

const ind = options.commentIndent === true
const ind = options.script.commentIndent === true
? indent
: 0;

Expand Down Expand Up @@ -334,7 +333,7 @@ prettify.beautify.script = (options: Options) => {
level.push(indent);
}

if (options.commentIndent === true && level[a] > -1 && data.lines[a] < 3) {
if (options.script.commentIndent === true && level[a] > -1 && data.lines[a] < 3) {
data.lines[a] = 3;
}
}
Expand Down Expand Up @@ -3164,9 +3163,10 @@ prettify.beautify.script = (options: Options) => {

level.push(indent);

} else {
} else if (ltype !== 'template' && data.types[a + 1] !== 'template') {

level.push(-10);

}

if (
Expand All @@ -3182,6 +3182,7 @@ prettify.beautify.script = (options: Options) => {

level[a - 1] = indent;
}

};

function template () {
Expand All @@ -3190,6 +3191,7 @@ prettify.beautify.script = (options: Options) => {
//
// Let's preserve occurances of Liquid tokens contained within
// JSON strings. This prevents extra spaces being applied.
//
if (options.language !== 'json' && data.types[a - 1] !== 'string') {

if (ctype === 'template_else') {
Expand Down Expand Up @@ -3832,7 +3834,8 @@ prettify.beautify.script = (options: Options) => {
// Improves the indentComment rule by aligning
// comments to the code they annotate.
//
if (data.types[a] === 'comment' && options.commentIndent === true) {
if (data.types[a] === 'comment' && options.script.commentIndent === true) {

if (/\n/.test(data.token[a])) {

const space = data.begin[a] > -1 ? data.token[a].charAt(2) === '*'
Expand All @@ -3856,7 +3859,9 @@ prettify.beautify.script = (options: Options) => {
if (invisibles.indexOf(data.token[a]) < 0) {

if (data.token[a] !== ';' || options.script.noSemicolon === false) {

build.push(data.token[a]);

} else if (levels[a] < 0 && data.types[a + 1] !== 'comment') {
build.push(';');
}
Expand Down Expand Up @@ -3917,6 +3922,7 @@ prettify.beautify.script = (options: Options) => {
prettify.start = a;

const ex = parse.beautify(lastLevel);

external = ex.beautify.replace(StripEnd, NIL);

build.push(external);
Expand Down

0 comments on commit 74f5ae4

Please sign in to comment.