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

fix: silence magic-string warnings and update usage #571

Merged
merged 1 commit into from
Nov 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 2 additions & 30 deletions src/patchers/NodePatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,7 @@ export default class NodePatcher {
/**
* Insert content at the specified index.
*/
insertLeft(index: number, content: string) {
if (typeof index !== 'number') {
throw new Error(
`cannot insert ${JSON.stringify(content)} at non-numeric index ${index}`
);
}
this.log(
'INSERT LEFT',
index,
JSON.stringify(content),
'AFTER',
JSON.stringify(this.context.source.slice(index - 8, index))
);

this.adjustBoundsToInclude(index);
this.editor.insertLeft(index, content);
}

/**
* Insert content at the specified index.
*/
insertRight(index: number, content: string) {
insert(index: number, content: string) {
if (typeof index !== 'number') {
throw new Error(
`cannot insert ${JSON.stringify(content)} at non-numeric index ${index}`
Expand All @@ -343,14 +322,7 @@ export default class NodePatcher {
);

this.adjustBoundsToInclude(index);
this.editor.insertLeft(index, content);
}

/**
* Alias for `#insertRight`.
*/
insert(index: number, content: string) {
this.insertRight(index, content);
this.editor.appendLeft(index, content);
}

allowPatchingOuterBounds(): boolean {
Expand Down
4 changes: 2 additions & 2 deletions src/patchers/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export type ParseContext = {
};

export type Editor = {
insertLeft: (index: number, content: string) => Editor;
insertRight: (index: number, content: string) => Editor;
appendLeft: (index: number, content: string) => Editor;
appendRight: (index: number, content: string) => Editor;
overwrite: (start: number, end: number, content: string) => Editor;
remove: (start: number, end: number) => Editor;
slice: (start: number, end: number) => string;
Expand Down
2 changes: 1 addition & 1 deletion src/stages/normalize/patchers/ConditionalPatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class ConditionalPatcher extends NodePatcher {
if (ifToken) {
let consequentCode = this.slice(this.consequent.outerStart, this.consequent.outerEnd);
this.remove(this.consequent.outerStart, ifToken.start);
this.insertRight(this.condition.outerEnd, ` then ${consequentCode}`);
this.insert(this.condition.outerEnd, ` then ${consequentCode}`);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/stages/semicolons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class SemicolonsStage {

asi(config);

config.insertions.forEach(({ index, content }) => editor.insertLeft(index, content));
config.insertions.forEach(({ index, content }) => editor.appendLeft(index, content));
config.removals.forEach(({ start, end }) => editor.remove(start, end));

return {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function escape(patcher: MagicString, characters: Array<string>|(
if (source[i] === '\\') {
i++;
} else if (predicate(source[i], i, source)) {
patcher.insertRight(i, '\\');
patcher.appendRight(i, '\\');
}
}
}
Expand Down