harper.js
Version:
The grammar checker that respects your privacy.
2,951 lines • 90.5 kB
JavaScript
// \0rolldown/runtime.js
var __defProp = Object.defineProperty;
var __exportAll = (all, no_symbols) => {
let target = {};
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
return target;
};
// ../../harper-wasm/pkg/harper_wasm_slim.js
var harper_wasm_slim_exports = /* @__PURE__ */ __exportAll({
Dialect: () => Dialect$1,
Language: () => Language$1,
Lint: () => Lint$1,
Linter: () => Linter$1,
OrganizedGroup: () => OrganizedGroup$1,
Span: () => Span$1,
Suggestion: () => Suggestion$1,
SuggestionKind: () => SuggestionKind$1,
default: () => __wbg_init$1,
get_default_lint_config: () => get_default_lint_config$1,
get_default_lint_config_as_json: () => get_default_lint_config_as_json$1,
initSync: () => initSync$1,
setup: () => setup$1,
to_title_case: () => to_title_case$1
});
/**
* Specifies an English Dialect, often used for linting.
* @enum {0 | 1 | 2 | 3 | 4}
*/
var Dialect$1 = Object.freeze({
American: 0,
"0": "American",
British: 1,
"1": "British",
Australian: 2,
"2": "Australian",
Canadian: 3,
"3": "Canadian",
Indian: 4,
"4": "Indian"
});
/**
* @enum {0 | 1 | 2}
*/
var Language$1 = Object.freeze({
Plain: 0,
"0": "Plain",
Markdown: 1,
"1": "Markdown",
Typst: 2,
"2": "Typst"
});
/**
* An error found in provided text.
*
* May include zero or more suggestions that may fix the problematic text.
*/
var Lint$1 = class Lint$1 {
static __wrap(ptr) {
const obj = Object.create(Lint$1.prototype);
obj.__wbg_ptr = ptr;
LintFinalization$1.register(obj, obj.__wbg_ptr, obj);
return obj;
}
static __unwrap(jsValue) {
if (!(jsValue instanceof Lint$1)) return 0;
return jsValue.__destroy_into_raw();
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
LintFinalization$1.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm$1.__wbg_lint_free(ptr, 0);
}
/**
* @param {string} json
* @returns {Lint}
*/
static from_json(json) {
const ptr0 = passStringToWasm0$1(json, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const ret = wasm$1.lint_from_json(ptr0, WASM_VECTOR_LEN$1);
if (ret[2]) throw takeFromExternrefTable0$1(ret[1]);
return Lint$1.__wrap(ret[0]);
}
/**
* Get the content of the source material pointed to by [`Self::span`]
* @returns {string}
*/
get_problem_text() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_get_problem_text(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a string representing the general category of the lint.
* @returns {string}
*/
lint_kind() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_lint_kind(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a string representing the general category of the lint.
* @returns {string}
*/
lint_kind_pretty() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_lint_kind_pretty(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a description of the error.
* @returns {string}
*/
message() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_message(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a description of the error as HTML.
* @returns {string}
*/
message_html() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_message_html(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get the location of the problematic text.
* @returns {Span}
*/
span() {
const ret = wasm$1.lint_span(this.__wbg_ptr);
return Span$1.__wrap(ret);
}
/**
* Equivalent to calling `.length` on the result of `suggestions()`.
* @returns {number}
*/
suggestion_count() {
return wasm$1.lint_suggestion_count(this.__wbg_ptr) >>> 0;
}
/**
* Get an array of any suggestions that may resolve the issue.
* @returns {Suggestion[]}
*/
suggestions() {
const ret = wasm$1.lint_suggestions(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0$1(ret[0], ret[1]);
wasm$1.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.lint_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Lint$1.prototype[Symbol.dispose] = Lint$1.prototype.free;
var Linter$1 = class Linter$1 {
static __wrap(ptr) {
const obj = Object.create(Linter$1.prototype);
obj.__wbg_ptr = ptr;
LinterFinalization$1.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
LinterFinalization$1.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm$1.__wbg_linter_free(ptr, 0);
}
/**
* Apply a suggestion from a given lint.
* This action will be logged to the Linter's statistics.
* @param {string} source_text
* @param {Lint} lint
* @param {Suggestion} suggestion
* @returns {string}
*/
apply_suggestion(source_text, lint, suggestion) {
let deferred3_0;
let deferred3_1;
try {
const ptr0 = passStringToWasm0$1(source_text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
_assertClass$1(lint, Lint$1);
_assertClass$1(suggestion, Suggestion$1);
const ret = wasm$1.linter_apply_suggestion(this.__wbg_ptr, ptr0, len0, lint.__wbg_ptr, suggestion.__wbg_ptr);
var ptr2 = ret[0];
var len2 = ret[1];
if (ret[3]) {
ptr2 = 0;
len2 = 0;
throw takeFromExternrefTable0$1(ret[2]);
}
deferred3_0 = ptr2;
deferred3_1 = len2;
return getStringFromWasm0$1(ptr2, len2);
} finally {
wasm$1.__wbindgen_free(deferred3_0, deferred3_1, 1);
}
}
clear_ignored_lints() {
wasm$1.linter_clear_ignored_lints(this.__wbg_ptr);
}
/**
* Clear the user dictionary.
*/
clear_words() {
wasm$1.linter_clear_words(this.__wbg_ptr);
}
/**
* Compute the context hash of a given lint.
* @param {string} source_text
* @param {Lint} lint
* @returns {bigint}
*/
context_hash(source_text, lint) {
const ptr0 = passStringToWasm0$1(source_text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
_assertClass$1(lint, Lint$1);
const ret = wasm$1.linter_context_hash(this.__wbg_ptr, ptr0, len0, lint.__wbg_ptr);
return BigInt.asUintN(64, ret);
}
/**
* Export the linter's ignored lints as a privacy-respecting JSON list of hashes.
* @returns {string}
*/
export_ignored_lints() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_export_ignored_lints(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Export words from the dictionary.
* Note: this will only return words previously added by [`Self::import_words`].
* @returns {string[]}
*/
export_words() {
const ret = wasm$1.linter_export_words(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0$1(ret[0], ret[1]);
wasm$1.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @returns {string}
*/
generate_stats_file() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_generate_stats_file(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get the dialect this struct was constructed for.
* @returns {Dialect}
*/
get_dialect() {
return wasm$1.linter_get_dialect(this.__wbg_ptr);
}
/**
* @returns {string}
*/
get_lint_config_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_get_lint_config_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {any}
*/
get_lint_config_as_object() {
return wasm$1.linter_get_lint_config_as_object(this.__wbg_ptr);
}
/**
* Get a JSON map containing the descriptions of all the linting rules, formatted as Markdown.
* @returns {string}
*/
get_lint_descriptions_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_get_lint_descriptions_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a Record containing the descriptions of all the linting rules, formatted as Markdown.
* @returns {any}
*/
get_lint_descriptions_as_object() {
return wasm$1.linter_get_lint_descriptions_as_object(this.__wbg_ptr);
}
/**
* Get a JSON map containing the descriptions of all the linting rules, formatted as HTML.
* @returns {string}
*/
get_lint_descriptions_html_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_get_lint_descriptions_html_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a Record containing the descriptions of all the linting rules, formatted as HTML.
* @returns {any}
*/
get_lint_descriptions_html_as_object() {
return wasm$1.linter_get_lint_descriptions_html_as_object(this.__wbg_ptr);
}
/**
* @returns {string}
*/
get_structured_lint_config_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.linter_get_structured_lint_config_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {any}
*/
get_structured_lint_config_as_object() {
return wasm$1.linter_get_structured_lint_config_as_object(this.__wbg_ptr);
}
/**
* Add a specific context hash to the ignored lints list.
* @param {BigUint64Array} hashes
*/
ignore_hashes(hashes) {
const ptr0 = passArray64ToWasm0$1(hashes, wasm$1.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN$1;
wasm$1.linter_ignore_hashes(this.__wbg_ptr, ptr0, len0);
}
/**
* @param {string} source_text
* @param {Lint[]} lints
*/
ignore_lints(source_text, lints) {
const ptr0 = passStringToWasm0$1(source_text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
const ptr1 = passArrayJsValueToWasm0$1(lints, wasm$1.__wbindgen_malloc);
const len1 = WASM_VECTOR_LEN$1;
wasm$1.linter_ignore_lints(this.__wbg_ptr, ptr0, len0, ptr1, len1);
}
/**
* Import into the linter's ignored lints from a privacy-respecting JSON list of hashes.
* @param {string} json
*/
import_ignored_lints(json) {
const ptr0 = passStringToWasm0$1(json, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_import_ignored_lints(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0$1(ret[0]);
}
/**
* @param {string} file
*/
import_stats_file(file) {
const ptr0 = passStringToWasm0$1(file, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_import_stats_file(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0$1(ret[0]);
}
/**
* Load a Weirpack from raw bytes, merging its rules into the current linter.
* Returns test failures if any are found, and does not import in that case.
* @param {Uint8Array} bytes
* @returns {any}
*/
import_weirpack(bytes) {
const ptr0 = passArray8ToWasm0$1(bytes, wasm$1.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_import_weirpack(this.__wbg_ptr, ptr0, len0);
if (ret[2]) throw takeFromExternrefTable0$1(ret[1]);
return takeFromExternrefTable0$1(ret[0]);
}
/**
* Import words into the dictionary.
* @param {string[]} additional_words
*/
import_words(additional_words) {
const ptr0 = passArrayJsValueToWasm0$1(additional_words, wasm$1.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN$1;
wasm$1.linter_import_words(this.__wbg_ptr, ptr0, len0);
}
/**
* Helper method to quickly check if a plain string is likely intended to be English
* @param {string} text
* @returns {boolean}
*/
is_likely_english(text) {
const ptr0 = passStringToWasm0$1(text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
return wasm$1.linter_is_likely_english(this.__wbg_ptr, ptr0, len0) !== 0;
}
/**
* Helper method to remove non-English text from a plain English document.
* @param {string} text
* @returns {string}
*/
isolate_english(text) {
let deferred2_0;
let deferred2_1;
try {
const ptr0 = passStringToWasm0$1(text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_isolate_english(this.__wbg_ptr, ptr0, len0);
deferred2_0 = ret[0];
deferred2_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}
/**
* Perform the configured linting on the provided text.
*
* If the provided regex mask cannot be parsed, this method will return an empty array.
* @param {string} text
* @param {Language} language
* @param {boolean} all_headings
* @param {string | null | undefined} regex_mask
* @param {boolean} dedup
* @param {boolean} isolate_english
* @returns {Lint[]}
*/
lint(text, language, all_headings, regex_mask, dedup, isolate_english) {
const ptr0 = passStringToWasm0$1(text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
var ptr1 = isLikeNone$1(regex_mask) ? 0 : passStringToWasm0$1(regex_mask, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_lint(this.__wbg_ptr, ptr0, len0, language, all_headings, ptr1, len1, dedup, isolate_english);
var v3 = getArrayJsValueFromWasm0$1(ret[0], ret[1]);
wasm$1.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v3;
}
/**
* Construct a new `Linter`.
* Note that this can mean constructing the curated dictionary, which is the most expensive operation
* in Harper.
* @param {Dialect} dialect
* @returns {Linter}
*/
static new(dialect) {
const ret = wasm$1.linter_new(dialect);
return Linter$1.__wrap(ret);
}
/**
* @param {string} text
* @param {Language} language
* @param {boolean} all_headings
* @param {string | null | undefined} regex_mask
* @param {boolean} dedup
* @param {boolean} isolate_english
* @returns {OrganizedGroup[]}
*/
organized_lints(text, language, all_headings, regex_mask, dedup, isolate_english) {
const ptr0 = passStringToWasm0$1(text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
var ptr1 = isLikeNone$1(regex_mask) ? 0 : passStringToWasm0$1(regex_mask, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_organized_lints(this.__wbg_ptr, ptr0, len0, language, all_headings, ptr1, len1, dedup, isolate_english);
var v3 = getArrayJsValueFromWasm0$1(ret[0], ret[1]);
wasm$1.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v3;
}
/**
* @param {string} json
*/
set_lint_config_from_json(json) {
const ptr0 = passStringToWasm0$1(json, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
const ret = wasm$1.linter_set_lint_config_from_json(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0$1(ret[0]);
}
/**
* @param {any} object
*/
set_lint_config_from_object(object) {
const ret = wasm$1.linter_set_lint_config_from_object(this.__wbg_ptr, object);
if (ret[1]) throw takeFromExternrefTable0$1(ret[0]);
}
/**
* @param {bigint | null} [start_time]
* @param {bigint | null} [end_time]
* @returns {any}
*/
summarize_stats(start_time, end_time) {
return wasm$1.linter_summarize_stats(this.__wbg_ptr, !isLikeNone$1(start_time), isLikeNone$1(start_time) ? BigInt(0) : start_time, !isLikeNone$1(end_time), isLikeNone$1(end_time) ? BigInt(0) : end_time);
}
};
if (Symbol.dispose) Linter$1.prototype[Symbol.dispose] = Linter$1.prototype.free;
/**
* Used exclusively for [`Linter::organized_lints`]
*/
var OrganizedGroup$1 = class OrganizedGroup$1 {
static __wrap(ptr) {
const obj = Object.create(OrganizedGroup$1.prototype);
obj.__wbg_ptr = ptr;
OrganizedGroupFinalization$1.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
OrganizedGroupFinalization$1.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm$1.__wbg_organizedgroup_free(ptr, 0);
}
/**
* @returns {string}
*/
get group() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.__wbg_get_organizedgroup_group(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {Lint[]}
*/
get lints() {
const ret = wasm$1.__wbg_get_organizedgroup_lints(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0$1(ret[0], ret[1]);
wasm$1.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @param {string} arg0
*/
set group(arg0) {
const ptr0 = passStringToWasm0$1(arg0, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN$1;
wasm$1.__wbg_set_organizedgroup_group(this.__wbg_ptr, ptr0, len0);
}
/**
* @param {Lint[]} arg0
*/
set lints(arg0) {
const ptr0 = passArrayJsValueToWasm0$1(arg0, wasm$1.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN$1;
wasm$1.__wbg_set_organizedgroup_lints(this.__wbg_ptr, ptr0, len0);
}
};
if (Symbol.dispose) OrganizedGroup$1.prototype[Symbol.dispose] = OrganizedGroup$1.prototype.free;
/**
* A struct that represents two character indices in a string: a start and an end.
*/
var Span$1 = class Span$1 {
static __wrap(ptr) {
const obj = Object.create(Span$1.prototype);
obj.__wbg_ptr = ptr;
SpanFinalization$1.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
SpanFinalization$1.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm$1.__wbg_span_free(ptr, 0);
}
/**
* @returns {number}
*/
get end() {
return wasm$1.__wbg_get_span_end(this.__wbg_ptr) >>> 0;
}
/**
* @returns {number}
*/
get start() {
return wasm$1.__wbg_get_span_start(this.__wbg_ptr) >>> 0;
}
/**
* @param {number} arg0
*/
set end(arg0) {
wasm$1.__wbg_set_span_end(this.__wbg_ptr, arg0);
}
/**
* @param {number} arg0
*/
set start(arg0) {
wasm$1.__wbg_set_span_start(this.__wbg_ptr, arg0);
}
/**
* @param {string} json
* @returns {Span}
*/
static from_json(json) {
const ptr0 = passStringToWasm0$1(json, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const ret = wasm$1.span_from_json(ptr0, WASM_VECTOR_LEN$1);
if (ret[2]) throw takeFromExternrefTable0$1(ret[1]);
return Span$1.__wrap(ret[0]);
}
/**
* @returns {boolean}
*/
is_empty() {
return wasm$1.span_is_empty(this.__wbg_ptr) !== 0;
}
/**
* @returns {number}
*/
len() {
return wasm$1.span_len(this.__wbg_ptr) >>> 0;
}
/**
* @param {number} start
* @param {number} end
* @returns {Span}
*/
static new(start, end) {
const ret = wasm$1.span_new(start, end);
return Span$1.__wrap(ret);
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.span_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Span$1.prototype[Symbol.dispose] = Span$1.prototype.free;
/**
* A suggestion to fix a Lint.
*/
var Suggestion$1 = class Suggestion$1 {
static __wrap(ptr) {
const obj = Object.create(Suggestion$1.prototype);
obj.__wbg_ptr = ptr;
SuggestionFinalization$1.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
SuggestionFinalization$1.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm$1.__wbg_suggestion_free(ptr, 0);
}
/**
* @param {string} json
* @returns {Suggestion}
*/
static from_json(json) {
const ptr0 = passStringToWasm0$1(json, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const ret = wasm$1.suggestion_from_json(ptr0, WASM_VECTOR_LEN$1);
if (ret[2]) throw takeFromExternrefTable0$1(ret[1]);
return Suggestion$1.__wrap(ret[0]);
}
/**
* Get the text that is going to replace the problematic section.
* If [`Self::kind`] is `SuggestionKind::Remove`, this will return an empty
* string.
* @returns {string}
*/
get_replacement_text() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.suggestion_get_replacement_text(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {SuggestionKind}
*/
kind() {
return wasm$1.suggestion_kind(this.__wbg_ptr);
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.suggestion_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Suggestion$1.prototype[Symbol.dispose] = Suggestion$1.prototype.free;
/**
* Tags the variant of suggestion.
* @enum {0 | 1 | 2}
*/
var SuggestionKind$1 = Object.freeze({
/**
* Replace the problematic text.
*/
Replace: 0,
"0": "Replace",
/**
* Remove the problematic text.
*/
Remove: 1,
"1": "Remove",
/**
* Insert additional text after the error.
*/
InsertAfter: 2,
"2": "InsertAfter"
});
/**
* @returns {any}
*/
function get_default_lint_config$1() {
return wasm$1.get_default_lint_config();
}
/**
* @returns {string}
*/
function get_default_lint_config_as_json$1() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm$1.get_default_lint_config_as_json();
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Set up the WebAssembly module's logging.
*/
function setup$1() {
wasm$1.setup();
}
/**
* @param {string} text
* @returns {string}
*/
function to_title_case$1(text) {
let deferred2_0;
let deferred2_1;
try {
const ptr0 = passStringToWasm0$1(text, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const ret = wasm$1.to_title_case(ptr0, WASM_VECTOR_LEN$1);
deferred2_0 = ret[0];
deferred2_1 = ret[1];
return getStringFromWasm0$1(ret[0], ret[1]);
} finally {
wasm$1.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}
function __wbg_get_imports$1() {
return {
__proto__: null,
"./harper_wasm_slim_bg.js": {
__proto__: null,
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
return Error(getStringFromWasm0$1(arg0, arg1));
},
__wbg_String_8564e559799eccda: function(arg0, arg1) {
const ptr1 = passStringToWasm0$1(String(arg1), wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN$1;
getDataViewMemory0$1().setInt32(arg0 + 4, len1, true);
getDataViewMemory0$1().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
const v = arg0;
const ret = typeof v === "boolean" ? v : void 0;
return isLikeNone$1(ret) ? 16777215 : ret ? 1 : 0;
},
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
const ptr1 = passStringToWasm0$1(debugString$1(arg1), wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN$1;
getDataViewMemory0$1().setInt32(arg0 + 4, len1, true);
getDataViewMemory0$1().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
return typeof arg0 === "function";
},
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
const val = arg0;
return typeof val === "object" && val !== null;
},
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
return typeof arg0 === "string";
},
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
return arg0 == arg1;
},
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
const obj = arg1;
const ret = typeof obj === "number" ? obj : void 0;
getDataViewMemory0$1().setFloat64(arg0 + 8, isLikeNone$1(ret) ? 0 : ret, true);
getDataViewMemory0$1().setInt32(arg0 + 0, !isLikeNone$1(ret), true);
},
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
const obj = arg1;
const ret = typeof obj === "string" ? obj : void 0;
var ptr1 = isLikeNone$1(ret) ? 0 : passStringToWasm0$1(ret, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN$1;
getDataViewMemory0$1().setInt32(arg0 + 4, len1, true);
getDataViewMemory0$1().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
throw new Error(getStringFromWasm0$1(arg0, arg1));
},
__wbg_call_6137034ef55c9d0f: function() {
return handleError$1(function(arg0, arg1) {
return arg0.call(arg1);
}, arguments);
},
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
return arg0.done;
},
__wbg_entries_fb6397112b1de25f: function(arg0) {
return Object.entries(arg0);
},
__wbg_error_757e9472f8410341: function(arg0, arg1) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.error(getStringFromWasm0$1(arg0, arg1));
} finally {
wasm$1.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_getRandomValues_973dabfb0ad1769f: function() {
return handleError$1(function(arg0, arg1) {
globalThis.crypto.getRandomValues(getArrayU8FromWasm0$1(arg0, arg1));
}, arguments);
},
__wbg_getRandomValues_a608c4436c19407a: function() {
return handleError$1(function(arg0, arg1) {
globalThis.crypto.getRandomValues(getArrayU8FromWasm0$1(arg0, arg1));
}, arguments);
},
__wbg_getTime_f5a55efff2585d5d: function(arg0) {
return arg0.getTime();
},
__wbg_get_658f6698067d9515: function() {
return handleError$1(function(arg0, arg1) {
return Reflect.get(arg0, arg1);
}, arguments);
},
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
return arg0[arg1 >>> 0];
},
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
return arg0[arg1 >>> 0];
},
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
let result;
try {
result = arg0 instanceof ArrayBuffer;
} catch (_) {
result = false;
}
return result;
},
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
let result;
try {
result = arg0 instanceof Uint8Array;
} catch (_) {
result = false;
}
return result;
},
__wbg_iterator_e3c31c892080e444: function() {
return Symbol.iterator;
},
__wbg_length_7f3c00c40364105e: function(arg0) {
return arg0.length;
},
__wbg_length_d4bdea10311bd9cf: function(arg0) {
return arg0.length;
},
__wbg_lint_new: function(arg0) {
return Lint$1.__wrap(arg0);
},
__wbg_lint_unwrap: function(arg0) {
return Lint$1.__unwrap(arg0);
},
__wbg_log_1f8cbb01c83d06c2: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.log(getStringFromWasm0$1(arg0, arg1), getStringFromWasm0$1(arg2, arg3), getStringFromWasm0$1(arg4, arg5), getStringFromWasm0$1(arg6, arg7));
} finally {
wasm$1.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_log_a54ca6b45e09078a: function(arg0, arg1) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.log(getStringFromWasm0$1(arg0, arg1));
} finally {
wasm$1.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_mark_6b7f03786f5e4d61: function(arg0, arg1) {
performance.mark(getStringFromWasm0$1(arg0, arg1));
},
__wbg_measure_0e21b33a1c6e3a29: function() {
return handleError$1(function(arg0, arg1, arg2, arg3) {
let deferred0_0;
let deferred0_1;
let deferred1_0;
let deferred1_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
deferred1_0 = arg2;
deferred1_1 = arg3;
performance.measure(getStringFromWasm0$1(arg0, arg1), getStringFromWasm0$1(arg2, arg3));
} finally {
wasm$1.__wbindgen_free(deferred0_0, deferred0_1, 1);
wasm$1.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}, arguments);
},
__wbg_new_0_72d020f0c63443d4: function() {
return /* @__PURE__ */ new Date();
},
__wbg_new_1dbf7428bba60a42: function(arg0) {
return new Uint8Array(arg0);
},
__wbg_new_227d7c05414eb861: function() {
return /* @__PURE__ */ new Error();
},
__wbg_new_28744009d011f847: function() {
return /* @__PURE__ */ new Map();
},
__wbg_new_617a8cdb8bb1130e: function() {
return /* @__PURE__ */ new Object();
},
__wbg_new_ee2291f50781bf1d: function() {
return new Array();
},
__wbg_next_33784799010f1bbe: function(arg0) {
return arg0.next;
},
__wbg_next_f4aac29c42af995c: function() {
return handleError$1(function(arg0) {
return arg0.next();
}, arguments);
},
__wbg_organizedgroup_new: function(arg0) {
return OrganizedGroup$1.__wrap(arg0);
},
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
Uint8Array.prototype.set.call(getArrayU8FromWasm0$1(arg0, arg1), arg2);
},
__wbg_set_6ae97e73113c4f0b: function(arg0, arg1, arg2) {
return arg0.set(arg1, arg2);
},
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
arg0[arg1] = arg2;
},
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
arg0[arg1 >>> 0] = arg2;
},
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
const ret = arg1.stack;
const ptr1 = passStringToWasm0$1(ret, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN$1;
getDataViewMemory0$1().setInt32(arg0 + 4, len1, true);
getDataViewMemory0$1().setInt32(arg0 + 0, ptr1, true);
},
__wbg_suggestion_new: function(arg0) {
return Suggestion$1.__wrap(arg0);
},
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
return arg0.value;
},
__wbindgen_generic_0000000000000001: function(arg0) {
return arg0;
},
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
return getStringFromWasm0$1(arg0, arg1);
},
__wbindgen_init_externref_table: function() {
const table = wasm$1.__wbindgen_externrefs;
const offset = table.grow(4);
table.set(0, void 0);
table.set(offset + 0, void 0);
table.set(offset + 1, null);
table.set(offset + 2, true);
table.set(offset + 3, false);
}
}
};
}
var LintFinalization$1 = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm$1.__wbg_lint_free(ptr, 1));
var LinterFinalization$1 = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm$1.__wbg_linter_free(ptr, 1));
var OrganizedGroupFinalization$1 = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm$1.__wbg_organizedgroup_free(ptr, 1));
var SpanFinalization$1 = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm$1.__wbg_span_free(ptr, 1));
var SuggestionFinalization$1 = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm$1.__wbg_suggestion_free(ptr, 1));
function addToExternrefTable0$1(obj) {
const idx = wasm$1.__externref_table_alloc();
wasm$1.__wbindgen_externrefs.set(idx, obj);
return idx;
}
function _assertClass$1(instance, klass) {
if (!(instance instanceof klass)) throw new Error(`expected instance of ${klass.name}`);
}
function debugString$1(val) {
const type = typeof val;
if (type == "number" || type == "boolean" || val == null) return `${val}`;
if (type == "string") return `"${val}"`;
if (type == "symbol") {
const description = val.description;
if (description == null) return "Symbol";
else return `Symbol(${description})`;
}
if (type == "function") {
const name = val.name;
if (typeof name == "string" && name.length > 0) return `Function(${name})`;
else return "Function";
}
if (Array.isArray(val)) {
const length = val.length;
let debug = "[";
if (length > 0) debug += debugString$1(val[0]);
for (let i = 1; i < length; i++) debug += ", " + debugString$1(val[i]);
debug += "]";
return debug;
}
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches && builtInMatches.length > 1) className = builtInMatches[1];
else return toString.call(val);
if (className == "Object") try {
return "Object(" + JSON.stringify(val) + ")";
} catch (_) {
return "Object";
}
if (val instanceof Error) return `${val.name}: ${val.message}\n${val.stack}`;
return className;
}
function getArrayJsValueFromWasm0$1(ptr, len) {
ptr = ptr >>> 0;
const mem = getDataViewMemory0$1();
const result = [];
for (let i = ptr; i < ptr + 4 * len; i += 4) result.push(wasm$1.__wbindgen_externrefs.get(mem.getUint32(i, true)));
wasm$1.__externref_drop_slice(ptr, len);
return result;
}
function getArrayU8FromWasm0$1(ptr, len) {
ptr = ptr >>> 0;
return getUint8ArrayMemory0$1().subarray(ptr / 1, ptr / 1 + len);
}
var cachedBigUint64ArrayMemory0$1 = null;
function getBigUint64ArrayMemory0$1() {
if (cachedBigUint64ArrayMemory0$1 === null || cachedBigUint64ArrayMemory0$1.byteLength === 0) cachedBigUint64ArrayMemory0$1 = new BigUint64Array(wasm$1.memory.buffer);
return cachedBigUint64ArrayMemory0$1;
}
var cachedDataViewMemory0$1 = null;
function getDataViewMemory0$1() {
if (cachedDataViewMemory0$1 === null || cachedDataViewMemory0$1.buffer.detached === true || cachedDataViewMemory0$1.buffer.detached === void 0 && cachedDataViewMemory0$1.buffer !== wasm$1.memory.buffer) cachedDataViewMemory0$1 = new DataView(wasm$1.memory.buffer);
return cachedDataViewMemory0$1;
}
function getStringFromWasm0$1(ptr, len) {
return decodeText$1(ptr >>> 0, len);
}
var cachedUint8ArrayMemory0$1 = null;
function getUint8ArrayMemory0$1() {
if (cachedUint8ArrayMemory0$1 === null || cachedUint8ArrayMemory0$1.byteLength === 0) cachedUint8ArrayMemory0$1 = new Uint8Array(wasm$1.memory.buffer);
return cachedUint8ArrayMemory0$1;
}
function handleError$1(f, args) {
try {
return f.apply(this, args);
} catch (e) {
const idx = addToExternrefTable0$1(e);
wasm$1.__wbindgen_exn_store(idx);
}
}
function isLikeNone$1(x) {
return x === void 0 || x === null;
}
function passArray64ToWasm0$1(arg, malloc) {
const ptr = malloc(arg.length * 8, 8) >>> 0;
getBigUint64ArrayMemory0$1().set(arg, ptr / 8);
WASM_VECTOR_LEN$1 = arg.length;
return ptr;
}
function passArray8ToWasm0$1(arg, malloc) {
const ptr = malloc(arg.length * 1, 1) >>> 0;
getUint8ArrayMemory0$1().set(arg, ptr / 1);
WASM_VECTOR_LEN$1 = arg.length;
return ptr;
}
function passArrayJsValueToWasm0$1(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
for (let i = 0; i < array.length; i++) {
const add = addToExternrefTable0$1(array[i]);
getDataViewMemory0$1().setUint32(ptr + 4 * i, add, true);
}
WASM_VECTOR_LEN$1 = array.length;
return ptr;
}
function passStringToWasm0$1(arg, malloc, realloc) {
if (realloc === void 0) {
const buf = cachedTextEncoder$1.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0$1().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN$1 = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0$1();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 127) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) arg = arg.slice(offset);
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0$1().subarray(ptr + offset, ptr + len);
const ret = cachedTextEncoder$1.encodeInto(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN$1 = offset;
return ptr;
}
function takeFromExternrefTable0$1(idx) {
const value = wasm$1.__wbindgen_externrefs.get(idx);
wasm$1.__externref_table_dealloc(idx);
return value;
}
var cachedTextDecoder$1 = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder$1.decode();
var MAX_SAFARI_DECODE_BYTES$1 = 2146435072;
var numBytesDecoded$1 = 0;
function decodeText$1(ptr, len) {
numBytesDecoded$1 += len;
if (numBytesDecoded$1 >= MAX_SAFARI_DECODE_BYTES$1) {
cachedTextDecoder$1 = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder$1.decode();
numBytesDecoded$1 = len;
}
return cachedTextDecoder$1.decode(getUint8ArrayMemory0$1().subarray(ptr, ptr + len));
}
var cachedTextEncoder$1 = new TextEncoder();
if (!("encodeInto" in cachedTextEncoder$1)) cachedTextEncoder$1.encodeInto = function(arg, view) {
const buf = cachedTextEncoder$1.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
};
var WASM_VECTOR_LEN$1 = 0;
var wasm$1;
function __wbg_finalize_init$1(instance, module) {
wasm$1 = instance.exports;
cachedBigUint64ArrayMemory0$1 = null;
cachedDataViewMemory0$1 = null;
cachedUint8ArrayMemory0$1 = null;
wasm$1.__wbindgen_start();
return wasm$1;
}
async function __wbg_load$1(module, imports) {
if (typeof Response === "function" && module instanceof Response) {
if (!module.ok) throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
if (typeof WebAssembly.instantiateStreaming === "function") try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
else throw e;
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) return {
instance,
module
};
else return instance;
}
function expectedResponseType(type) {
switch (type) {
case "basic":
case "cors":
case "default": return true;
}
return false;
}
}
function initSync$1(module) {
if (wasm$1 !== void 0) return wasm$1;
if (module !== void 0) {
if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
}
const imports = __wbg_get_imports$1();
if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
return __wbg_finalize_init$1(new WebAssembly.Instance(module, imports), module);
}
async function __wbg_init$1(module_or_path) {
if (wasm$1 !== void 0) return wasm$1;
if (module_or_path !== void 0) {
if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
}
if (module_or_path === void 0) module_or_path = new URL();
const imports = __wbg_get_imports$1();
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
const { instance, module } = await __wbg_load$1(await module_or_path, imports);
return __wbg_finalize_init$1(instance, module);
}
// ../../harper-wasm/pkg/harper_wasm.js
var harper_wasm_exports = /* @__PURE__ */ __exportAll({
Dialect: () => Dialect,
Language: () => Language,
Lint: () => Lint,
Linter: () => Linter,
OrganizedGroup: () => OrganizedGroup,
Span: () => Span,
Suggestion: () => Suggestion,
SuggestionKind: () => SuggestionKind,
default: () => __wbg_init,
get_default_lint_config: () => get_default_lint_config,
get_default_lint_config_as_json: () => get_default_lint_config_as_json,
initSync: () => initSync,
setup: () => setup,
to_title_case: () => to_title_case
});
/**
* Specifies an English Dialect, often used for linting.
* @enum {0 | 1 | 2 | 3 | 4}
*/
var Dialect = Object.freeze({
American: 0,
"0": "American",
British: 1,
"1": "British",
Australian: 2,
"2": "Australian",
Canadian: 3,
"3": "Canadian",
Indian: 4,
"4": "Indian"
});
/**
* @enum {0 | 1 | 2}
*/
var Language = Object.freeze({
Plain: 0,
"0": "Plain",
Markdown: 1,
"1": "Markdown",
Typst: 2,
"2": "Typst"
});
/**
* An error found in provided text.
*
* May include zero or more suggestions that may fix the problematic text.
*/
var Lint = class Lint {
static __wrap(ptr) {
const obj = Object.create(Lint.prototype);
obj.__wbg_ptr = ptr;
LintFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
static __unwrap(jsValue) {
if (!(jsValue instanceof Lint)) return 0;
return jsValue.__destroy_into_raw();
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
LintFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_lint_free(ptr, 0);
}
/**
* @param {string} json
* @returns {Lint}
*/
static from_json(json) {
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ret = wasm.lint_from_json(ptr0, WASM_VECTOR_LEN);
if (ret[2]) throw takeFromExternrefTable0(ret[1]);
return Lint.__wrap(ret[0]);
}
/**
* Get the content of the source material pointed to by [`Self::span`]
* @returns {string}
*/
get_problem_text() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_get_problem_text(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a string representing the general category of the lint.
* @returns {string}
*/
lint_kind() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_lint_kind(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a string representing the general category of the lint.
* @returns {string}
*/
lint_kind_pretty() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_lint_kind_pretty(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a description of the error.
* @returns {string}
*/
message() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_message(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a description of the error as HTML.
* @returns {string}
*/
message_html() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_message_html(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get the location of the problematic text.
* @returns {Span}
*/
span() {
const ret = wasm.lint_span(this.__wbg_ptr);
return Span.__wrap(ret);
}
/**
* Equivalent to calling `.length` on the result of `suggestions()`.
* @returns {number}
*/
suggestion_count() {
return wasm.lint_suggestion_count(this.__wbg_ptr) >>> 0;
}
/**
* Get an array of any suggestions that may resolve the issue.
* @returns {Suggestion[]}
*/
suggestions() {
const ret = wasm.lint_suggestions(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.lint_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Lint.prototype[Symbol.dispose] = Lint.prototype.free;
var Linter = class Linter {
static __wrap(ptr) {
const obj = Object.create(Linter.prototype);
obj.__wbg_ptr = ptr;
LinterFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
LinterFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_linter_free(ptr, 0);
}
/**
* Apply a suggestion from a given lint.
* This action will be logged to the Linter's statistics.
* @param {string} source_text
* @param {Lint} lint
* @param {Suggestion} suggestion
* @returns {string}
*/
apply_suggestion(source_text, lint, suggestion) {
let deferred3_0;
let deferred3_1;
try {
const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
_assertClass(lint, Lint);
_assertClass(suggestion, Suggestion);
const ret = wasm.linter_apply_suggestion(this.__wbg_ptr, ptr0, len0, lint.__wbg_ptr, suggestion.__wbg_ptr);
var ptr2 = ret[0];
var len2 = ret[1];
if (ret[3]) {
ptr2 = 0;
len2 = 0;
throw takeFromExternrefTable0(ret[2]);
}
deferred3_0 = ptr2;
deferred3_1 = len2;
return getStringFromWasm0(ptr2, len2);
} finally {
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
}
}
clear_ignored_lints() {
wasm.linter_clear_ignored_lints(this.__wbg_ptr);
}
/**
* Clear the user dictionary.
*/
clear_words() {
wasm.linter_clear_words(this.__wbg_ptr);
}
/**
* Compute the context hash of a given lint.
* @param {string} source_text
* @param {Lint} lint
* @returns {bigint}
*/
context_hash(source_text, lint) {
const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
_assertClass(lint, Lint);
const ret = wasm.linter_context_hash(this.__wbg_ptr, ptr0, len0, lint.__wbg_ptr);
return BigInt.asUintN(64, ret);
}
/**
* Export the linter's ignored lints as a privacy-respecting JSON list of hashes.
* @returns {string}
*/
export_ignored_lints() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_export_ignored_lints(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Export words from the dictionary.
* Note: this will only return words previously added by [`Self::import_words`].
* @returns {string[]}
*/
export_words() {
const ret = wasm.linter_export_words(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @returns {string}
*/
generate_stats_file() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_generate_stats_file(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get the dialect this struct was constructed for.
* @returns {Dialect}
*/
get_dialect() {
return wasm.linter_get_dialect(this.__wbg_ptr);
}
/**
* @returns {string}
*/
get_lint_config_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_get_lint_config_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {any}
*/
get_lint_config_as_object() {
return wasm.linter_get_lint_config_as_object(this.__wbg_ptr);
}
/**
* Get a JSON map containing the descriptions of all the linting rules, formatted as Markdown.
* @returns {string}
*/
get_lint_descriptions_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_get_lint_descriptions_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a Record containing the descriptions of all the linting rules, formatted as Markdown.
* @returns {any}
*/
get_lint_descriptions_as_object() {
return wasm.linter_get_lint_descriptions_as_object(this.__wbg_ptr);
}
/**
* Get a JSON map containing the descriptions of all the linting rules, formatted as HTML.
* @returns {string}
*/
get_lint_descriptions_html_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_get_lint_descriptions_html_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Get a Record containing the descriptions of all the linting rules, formatted as HTML.
* @returns {any}
*/
get_lint_descriptions_html_as_object() {
return wasm.linter_get_lint_descriptions_html_as_object(this.__wbg_ptr);
}
/**
* @returns {string}
*/
get_structured_lint_config_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.linter_get_structured_lint_config_as_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {any}
*/
get_structured_lint_config_as_object() {
return wasm.linter_get_structured_lint_config_as_object(this.__wbg_ptr);
}
/**
* Add a specific context hash to the ignored lints list.
* @param {BigUint64Array} hashes
*/
ignore_hashes(hashes) {
const ptr0 = passArray64ToWasm0(hashes, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
wasm.linter_ignore_hashes(this.__wbg_ptr, ptr0, len0);
}
/**
* @param {string} source_text
* @param {Lint[]} lints
*/
ignore_lints(source_text, lints) {
const ptr0 = passStringToWasm0(source_text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passArrayJsValueToWasm0(lints, wasm.__wbindgen_malloc);
const len1 = WASM_VECTOR_LEN;
wasm.linter_ignore_lints(this.__wbg_ptr, ptr0, len0, ptr1, len1);
}
/**
* Import into the linter's ignored lints from a privacy-respecting JSON list of hashes.
* @param {string} json
*/
import_ignored_lints(json) {
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.linter_import_ignored_lints(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0(ret[0]);
}
/**
* @param {string} file
*/
import_stats_file(file) {
const ptr0 = passStringToWasm0(file, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.linter_import_stats_file(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0(ret[0]);
}
/**
* Load a Weirpack from raw bytes, merging its rules into the current linter.
* Returns test failures if any are found, and does not import in that case.
* @param {Uint8Array} bytes
* @returns {any}
*/
import_weirpack(bytes) {
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.linter_import_weirpack(this.__wbg_ptr, ptr0, len0);
if (ret[2]) throw takeFromExternrefTable0(ret[1]);
return takeFromExternrefTable0(ret[0]);
}
/**
* Import words into the dictionary.
* @param {string[]} additional_words
*/
import_words(additional_words) {
const ptr0 = passArrayJsValueToWasm0(additional_words, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
wasm.linter_import_words(this.__wbg_ptr, ptr0, len0);
}
/**
* Helper method to quickly check if a plain string is likely intended to be English
* @param {string} text
* @returns {boolean}
*/
is_likely_english(text) {
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
return wasm.linter_is_likely_english(this.__wbg_ptr, ptr0, len0) !== 0;
}
/**
* Helper method to remove non-English text from a plain English document.
* @param {string} text
* @returns {string}
*/
isolate_english(text) {
let deferred2_0;
let deferred2_1;
try {
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.linter_isolate_english(this.__wbg_ptr, ptr0, len0);
deferred2_0 = ret[0];
deferred2_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}
/**
* Perform the configured linting on the provided text.
*
* If the provided regex mask cannot be parsed, this method will return an empty array.
* @param {string} text
* @param {Language} language
* @param {boolean} all_headings
* @param {string | null | undefined} regex_mask
* @param {boolean} dedup
* @param {boolean} isolate_english
* @returns {Lint[]}
*/
lint(text, language, all_headings, regex_mask, dedup, isolate_english) {
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
var ptr1 = isLikeNone(regex_mask) ? 0 : passStringToWasm0(regex_mask, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
const ret = wasm.linter_lint(this.__wbg_ptr, ptr0, len0, language, all_headings, ptr1, len1, dedup, isolate_english);
var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]);
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v3;
}
/**
* Construct a new `Linter`.
* Note that this can mean constructing the curated dictionary, which is the most expensive operation
* in Harper.
* @param {Dialect} dialect
* @returns {Linter}
*/
static new(dialect) {
const ret = wasm.linter_new(dialect);
return Linter.__wrap(ret);
}
/**
* @param {string} text
* @param {Language} language
* @param {boolean} all_headings
* @param {string | null | undefined} regex_mask
* @param {boolean} dedup
* @param {boolean} isolate_english
* @returns {OrganizedGroup[]}
*/
organized_lints(text, language, all_headings, regex_mask, dedup, isolate_english) {
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
var ptr1 = isLikeNone(regex_mask) ? 0 : passStringToWasm0(regex_mask, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
const ret = wasm.linter_organized_lints(this.__wbg_ptr, ptr0, len0, language, all_headings, ptr1, len1, dedup, isolate_english);
var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]);
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v3;
}
/**
* @param {string} json
*/
set_lint_config_from_json(json) {
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.linter_set_lint_config_from_json(this.__wbg_ptr, ptr0, len0);
if (ret[1]) throw takeFromExternrefTable0(ret[0]);
}
/**
* @param {any} object
*/
set_lint_config_from_object(object) {
const ret = wasm.linter_set_lint_config_from_object(this.__wbg_ptr, object);
if (ret[1]) throw takeFromExternrefTable0(ret[0]);
}
/**
* @param {bigint | null} [start_time]
* @param {bigint | null} [end_time]
* @returns {any}
*/
summarize_stats(start_time, end_time) {
return wasm.linter_summarize_stats(this.__wbg_ptr, !isLikeNone(start_time), isLikeNone(start_time) ? BigInt(0) : start_time, !isLikeNone(end_time), isLikeNone(end_time) ? BigInt(0) : end_time);
}
};
if (Symbol.dispose) Linter.prototype[Symbol.dispose] = Linter.prototype.free;
/**
* Used exclusively for [`Linter::organized_lints`]
*/
var OrganizedGroup = class OrganizedGroup {
static __wrap(ptr) {
const obj = Object.create(OrganizedGroup.prototype);
obj.__wbg_ptr = ptr;
OrganizedGroupFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
OrganizedGroupFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_organizedgroup_free(ptr, 0);
}
/**
* @returns {string}
*/
get group() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.__wbg_get_organizedgroup_group(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {Lint[]}
*/
get lints() {
const ret = wasm.__wbg_get_organizedgroup_lints(this.__wbg_ptr);
var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]);
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
return v1;
}
/**
* @param {string} arg0
*/
set group(arg0) {
const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len0 = WASM_VECTOR_LEN;
wasm.__wbg_set_organizedgroup_group(this.__wbg_ptr, ptr0, len0);
}
/**
* @param {Lint[]} arg0
*/
set lints(arg0) {
const ptr0 = passArrayJsValueToWasm0(arg0, wasm.__wbindgen_malloc);
const len0 = WASM_VECTOR_LEN;
wasm.__wbg_set_organizedgroup_lints(this.__wbg_ptr, ptr0, len0);
}
};
if (Symbol.dispose) OrganizedGroup.prototype[Symbol.dispose] = OrganizedGroup.prototype.free;
/**
* A struct that represents two character indices in a string: a start and an end.
*/
var Span = class Span {
static __wrap(ptr) {
const obj = Object.create(Span.prototype);
obj.__wbg_ptr = ptr;
SpanFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
SpanFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_span_free(ptr, 0);
}
/**
* @returns {number}
*/
get end() {
return wasm.__wbg_get_span_end(this.__wbg_ptr) >>> 0;
}
/**
* @returns {number}
*/
get start() {
return wasm.__wbg_get_span_start(this.__wbg_ptr) >>> 0;
}
/**
* @param {number} arg0
*/
set end(arg0) {
wasm.__wbg_set_span_end(this.__wbg_ptr, arg0);
}
/**
* @param {number} arg0
*/
set start(arg0) {
wasm.__wbg_set_span_start(this.__wbg_ptr, arg0);
}
/**
* @param {string} json
* @returns {Span}
*/
static from_json(json) {
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ret = wasm.span_from_json(ptr0, WASM_VECTOR_LEN);
if (ret[2]) throw takeFromExternrefTable0(ret[1]);
return Span.__wrap(ret[0]);
}
/**
* @returns {boolean}
*/
is_empty() {
return wasm.span_is_empty(this.__wbg_ptr) !== 0;
}
/**
* @returns {number}
*/
len() {
return wasm.span_len(this.__wbg_ptr) >>> 0;
}
/**
* @param {number} start
* @param {number} end
* @returns {Span}
*/
static new(start, end) {
const ret = wasm.span_new(start, end);
return Span.__wrap(ret);
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.span_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Span.prototype[Symbol.dispose] = Span.prototype.free;
/**
* A suggestion to fix a Lint.
*/
var Suggestion = class Suggestion {
static __wrap(ptr) {
const obj = Object.create(Suggestion.prototype);
obj.__wbg_ptr = ptr;
SuggestionFinalization.register(obj, obj.__wbg_ptr, obj);
return obj;
}
__destroy_into_raw() {
const ptr = this.__wbg_ptr;
this.__wbg_ptr = 0;
SuggestionFinalization.unregister(this);
return ptr;
}
free() {
const ptr = this.__destroy_into_raw();
wasm.__wbg_suggestion_free(ptr, 0);
}
/**
* @param {string} json
* @returns {Suggestion}
*/
static from_json(json) {
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ret = wasm.suggestion_from_json(ptr0, WASM_VECTOR_LEN);
if (ret[2]) throw takeFromExternrefTable0(ret[1]);
return Suggestion.__wrap(ret[0]);
}
/**
* Get the text that is going to replace the problematic section.
* If [`Self::kind`] is `SuggestionKind::Remove`, this will return an empty
* string.
* @returns {string}
*/
get_replacement_text() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.suggestion_get_replacement_text(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* @returns {SuggestionKind}
*/
kind() {
return wasm.suggestion_kind(this.__wbg_ptr);
}
/**
* @returns {string}
*/
to_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.suggestion_to_json(this.__wbg_ptr);
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
};
if (Symbol.dispose) Suggestion.prototype[Symbol.dispose] = Suggestion.prototype.free;
/**
* Tags the variant of suggestion.
* @enum {0 | 1 | 2}
*/
var SuggestionKind = Object.freeze({
/**
* Replace the problematic text.
*/
Replace: 0,
"0": "Replace",
/**
* Remove the problematic text.
*/
Remove: 1,
"1": "Remove",
/**
* Insert additional text after the error.
*/
InsertAfter: 2,
"2": "InsertAfter"
});
/**
* @returns {any}
*/
function get_default_lint_config() {
return wasm.get_default_lint_config();
}
/**
* @returns {string}
*/
function get_default_lint_config_as_json() {
let deferred1_0;
let deferred1_1;
try {
const ret = wasm.get_default_lint_config_as_json();
deferred1_0 = ret[0];
deferred1_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}
/**
* Set up the WebAssembly module's logging.
*/
function setup() {
wasm.setup();
}
/**
* @param {string} text
* @returns {string}
*/
function to_title_case(text) {
let deferred2_0;
let deferred2_1;
try {
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const ret = wasm.to_title_case(ptr0, WASM_VECTOR_LEN);
deferred2_0 = ret[0];
deferred2_1 = ret[1];
return getStringFromWasm0(ret[0], ret[1]);
} finally {
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
}
}
function __wbg_get_imports() {
return {
__proto__: null,
"./harper_wasm_bg.js": {
__proto__: null,
__wbg_Error_30c8987f7c2ed4e2: function(arg0, arg1) {
return Error(getStringFromWasm0(arg0, arg1));
},
__wbg_String_8564e559799eccda: function(arg0, arg1) {
const ptr1 = passStringToWasm0(String(arg1), wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_boolean_get_5b446f51afd21013: function(arg0) {
const v = arg0;
const ret = typeof v === "boolean" ? v : void 0;
return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
},
__wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
const ptr1 = passStringToWasm0(debugString(arg1), wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
return typeof arg0 === "function";
},
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
const val = arg0;
return typeof val === "object" && val !== null;
},
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
return typeof arg0 === "string";
},
__wbg___wbindgen_jsval_loose_eq_677f21e468d6b461: function(arg0, arg1) {
return arg0 == arg1;
},
__wbg___wbindgen_number_get_2e0e7dee9f701a71: function(arg0, arg1) {
const obj = arg1;
const ret = typeof obj === "number" ? obj : void 0;
getDataViewMemory0().setFloat64(arg0 + 8, isLikeNone(ret) ? 0 : ret, true);
getDataViewMemory0().setInt32(arg0 + 0, !isLikeNone(ret), true);
},
__wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
const obj = arg1;
const ret = typeof obj === "string" ? obj : void 0;
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
var len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
},
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
},
__wbg_call_6137034ef55c9d0f: function() {
return handleError(function(arg0, arg1) {
return arg0.call(arg1);
}, arguments);
},
__wbg_done_b41a1d26cdb37fb6: function(arg0) {
return arg0.done;
},
__wbg_entries_fb6397112b1de25f: function(arg0) {
return Object.entries(arg0);
},
__wbg_error_757e9472f8410341: function(arg0, arg1) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.error(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_getRandomValues_973dabfb0ad1769f: function() {
return handleError(function(arg0, arg1) {
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
}, arguments);
},
__wbg_getRandomValues_a608c4436c19407a: function() {
return handleError(function(arg0, arg1) {
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
}, arguments);
},
__wbg_getTime_f5a55efff2585d5d: function(arg0) {
return arg0.getTime();
},
__wbg_get_658f6698067d9515: function() {
return handleError(function(arg0, arg1) {
return Reflect.get(arg0, arg1);
}, arguments);
},
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
return arg0[arg1 >>> 0];
},
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
return arg0[arg1 >>> 0];
},
__wbg_instanceof_ArrayBuffer_a99f175873e5d9b8: function(arg0) {
let result;
try {
result = arg0 instanceof ArrayBuffer;
} catch (_) {
result = false;
}
return result;
},
__wbg_instanceof_Uint8Array_828cef2aaacafc31: function(arg0) {
let result;
try {
result = arg0 instanceof Uint8Array;
} catch (_) {
result = false;
}
return result;
},
__wbg_iterator_e3c31c892080e444: function() {
return Symbol.iterator;
},
__wbg_length_7f3c00c40364105e: function(arg0) {
return arg0.length;
},
__wbg_length_d4bdea10311bd9cf: function(arg0) {
return arg0.length;
},
__wbg_lint_new: function(arg0) {
return Lint.__wrap(arg0);
},
__wbg_lint_unwrap: function(arg0) {
return Lint.__unwrap(arg0);
},
__wbg_log_1f8cbb01c83d06c2: function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.log(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5), getStringFromWasm0(arg6, arg7));
} finally {
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_log_a54ca6b45e09078a: function(arg0, arg1) {
let deferred0_0;
let deferred0_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
console.log(getStringFromWasm0(arg0, arg1));
} finally {
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
}
},
__wbg_mark_6b7f03786f5e4d61: function(arg0, arg1) {
performance.mark(getStringFromWasm0(arg0, arg1));
},
__wbg_measure_0e21b33a1c6e3a29: function() {
return handleError(function(arg0, arg1, arg2, arg3) {
let deferred0_0;
let deferred0_1;
let deferred1_0;
let deferred1_1;
try {
deferred0_0 = arg0;
deferred0_1 = arg1;
deferred1_0 = arg2;
deferred1_1 = arg3;
performance.measure(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
} finally {
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
}, arguments);
},
__wbg_new_0_72d020f0c63443d4: function() {
return /* @__PURE__ */ new Date();
},
__wbg_new_1dbf7428bba60a42: function(arg0) {
return new Uint8Array(arg0);
},
__wbg_new_227d7c05414eb861: function() {
return /* @__PURE__ */ new Error();
},
__wbg_new_28744009d011f847: function() {
return /* @__PURE__ */ new Map();
},
__wbg_new_617a8cdb8bb1130e: function() {
return /* @__PURE__ */ new Object();
},
__wbg_new_ee2291f50781bf1d: function() {
return new Array();
},
__wbg_next_33784799010f1bbe: function(arg0) {
return arg0.next;
},
__wbg_next_f4aac29c42af995c: function() {
return handleError(function(arg0) {
return arg0.next();
}, arguments);
},
__wbg_organizedgroup_new: function(arg0) {
return OrganizedGroup.__wrap(arg0);
},
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
},
__wbg_set_6ae97e73113c4f0b: function(arg0, arg1, arg2) {
return arg0.set(arg1, arg2);
},
__wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
arg0[arg1] = arg2;
},
__wbg_set_bea140a88be9b277: function(arg0, arg1, arg2) {
arg0[arg1 >>> 0] = arg2;
},
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
const ret = arg1.stack;
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
},
__wbg_suggestion_new: function(arg0) {
return Suggestion.__wrap(arg0);
},
__wbg_value_f3c585ee8f5ba40c: function(arg0) {
return arg0.value;
},
__wbindgen_generic_0000000000000001: function(arg0) {
return arg0;
},
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
return getStringFromWasm0(arg0, arg1);
},
__wbindgen_init_externref_table: function() {
const table = wasm.__wbindgen_externrefs;
const offset = table.grow(4);
table.set(0, void 0);
table.set(offset + 0, void 0);
table.set(offset + 1, null);
table.set(offset + 2, true);
table.set(offset + 3, false);
}
}
};
}
var LintFinalization = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm.__wbg_lint_free(ptr, 1));
var LinterFinalization = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm.__wbg_linter_free(ptr, 1));
var OrganizedGroupFinalization = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm.__wbg_organizedgroup_free(ptr, 1));
var SpanFinalization = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm.__wbg_span_free(ptr, 1));
var SuggestionFinalization = typeof FinalizationRegistry === "undefined" ? {
register: () => {},
unregister: () => {}
} : new FinalizationRegistry((ptr) => wasm.__wbg_suggestion_free(ptr, 1));
function addToExternrefTable0(obj) {
const idx = wasm.__externref_table_alloc();
wasm.__wbindgen_externrefs.set(idx, obj);
return idx;
}
function _assertClass(instance, klass) {
if (!(instance instanceof klass)) throw new Error(`expected instance of ${klass.name}`);
}
function debugString(val) {
const type = typeof val;
if (type == "number" || type == "boolean" || val == null) return `${val}`;
if (type == "string") return `"${val}"`;
if (type == "symbol") {
const description = val.description;
if (description == null) return "Symbol";
else return `Symbol(${description})`;
}
if (type == "function") {
const name = val.name;
if (typeof name == "string" && name.length > 0) return `Function(${name})`;
else return "Function";
}
if (Array.isArray(val)) {
const length = val.length;
let debug = "[";
if (length > 0) debug += debugString(val[0]);
for (let i = 1; i < length; i++) debug += ", " + debugString(val[i]);
debug += "]";
return debug;
}
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches && builtInMatches.length > 1) className = builtInMatches[1];
else return toString.call(val);
if (className == "Object") try {
return "Object(" + JSON.stringify(val) + ")";
} catch (_) {
return "Object";
}
if (val instanceof Error) return `${val.name}: ${val.message}\n${val.stack}`;
return className;
}
function getArrayJsValueFromWasm0(ptr, len) {
ptr = ptr >>> 0;
const mem = getDataViewMemory0();
const result = [];
for (let i = ptr; i < ptr + 4 * len; i += 4) result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
wasm.__externref_drop_slice(ptr, len);
return result;
}
function getArrayU8FromWasm0(ptr, len) {
ptr = ptr >>> 0;
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
}
var cachedBigUint64ArrayMemory0 = null;
function getBigUint64ArrayMemory0() {
if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
return cachedBigUint64ArrayMemory0;
}
var cachedDataViewMemory0 = null;
function getDataViewMemory0() {
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
return cachedDataViewMemory0;
}
function getStringFromWasm0(ptr, len) {
return decodeText(ptr >>> 0, len);
}
var cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
return cachedUint8ArrayMemory0;
}
function handleError(f, args) {
try {
return f.apply(this, args);
} catch (e) {
const idx = addToExternrefTable0(e);
wasm.__wbindgen_exn_store(idx);
}
}
function isLikeNone(x) {
return x === void 0 || x === null;
}
function passArray64ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 8, 8) >>> 0;
getBigUint64ArrayMemory0().set(arg, ptr / 8);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
function passArray8ToWasm0(arg, malloc) {
const ptr = malloc(arg.length * 1, 1) >>> 0;
getUint8ArrayMemory0().set(arg, ptr / 1);
WASM_VECTOR_LEN = arg.length;
return ptr;
}
function passArrayJsValueToWasm0(array, malloc) {
const ptr = malloc(array.length * 4, 4) >>> 0;
for (let i = 0; i < array.length; i++) {
const add = addToExternrefTable0(array[i]);
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
}
WASM_VECTOR_LEN = array.length;
return ptr;
}
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === void 0) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 127) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) arg = arg.slice(offset);
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = cachedTextEncoder.encodeInto(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
function takeFromExternrefTable0(idx) {
const value = wasm.__wbindgen_externrefs.get(idx);
wasm.__externref_table_dealloc(idx);
return value;
}
var cachedTextDecoder = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder.decode();
var MAX_SAFARI_DECODE_BYTES = 2146435072;
var numBytesDecoded = 0;
function decodeText(ptr, len) {
numBytesDecoded += len;
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
cachedTextDecoder = new TextDecoder("utf-8", {
ignoreBOM: true,
fatal: true
});
cachedTextDecoder.decode();
numBytesDecoded = len;
}
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
var cachedTextEncoder = new TextEncoder();
if (!("encodeInto" in cachedTextEncoder)) cachedTextEncoder.encodeInto = function(arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
};
var WASM_VECTOR_LEN = 0;
var wasm;
function __wbg_finalize_init(instance, module) {
wasm = instance.exports;
cachedBigUint64ArrayMemory0 = null;
cachedDataViewMemory0 = null;
cachedUint8ArrayMemory0 = null;
wasm.__wbindgen_start();
return wasm;
}
async function __wbg_load(module, imports) {
if (typeof Response === "function" && module instanceof Response) {
if (!module.ok) throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
if (typeof WebAssembly.instantiateStreaming === "function") try {
return await WebAssembly.instantiateStreaming(module, imports);
} catch (e) {
if (expectedResponseType(module.type) && module.headers.get("Content-Type") !== "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
else throw e;
}
const bytes = await module.arrayBuffer();
return await WebAssembly.instantiate(bytes, imports);
} else {
const instance = await WebAssembly.instantiate(module, imports);
if (instance instanceof WebAssembly.Instance) return {
instance,
module
};
else return instance;
}
function expectedResponseType(type) {
switch (type) {
case "basic":
case "cors":
case "default": return true;
}
return false;
}
}
function initSync(module) {
if (wasm !== void 0) return wasm;
if (module !== void 0) {
if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
}
const imports = __wbg_get_imports();
if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
return __wbg_finalize_init(new WebAssembly.Instance(module, imports), module);
}
async function __wbg_init(module_or_path) {
if (wasm !== void 0) return wasm;
if (module_or_path !== void 0) {
if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
}
if (module_or_path === void 0) module_or_path = new URL();
const imports = __wbg_get_imports();
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
const { instance, module } = await __wbg_load(await module_or_path, imports);
return __wbg_finalize_init(instance, module);
}
// ../../node_modules/.pnpm/p-lazy@5.0.0/node_modules/p-lazy/index.js
var PLazy = class PLazy extends Promise {
#executor;
#promise;
constructor(executor) {
super((resolve) => {
resolve();
});
this.#executor = executor;
}
static from(function_) {
return new PLazy((resolve) => {
resolve(function_());
});
}
static resolve(value) {
return new PLazy((resolve) => {
resolve(value);
});
}
static reject(error) {
return new PLazy((resolve, reject) => {
reject(error);
});
}
then(onFulfilled, onRejected) {
this.#promise ??= new Promise(this.#executor);
return this.#promise.then(onFulfilled, onRejected);
}
catch(onRejected) {
this.#promise ??= new Promise(this.#executor);
return this.#promise.catch(onRejected);
}
finally(onFinally) {
this.#promise ??= new Promise(this.#executor);
return this.#promise.finally(onFinally);
}
};
// ../../node_modules/.pnpm/mimic-fn@4.0.0/node_modules/mimic-fn/index.js
var copyProperty = (to, from, property, ignoreNonConfigurable) => {
if (property === "length" || property === "prototype") return;
if (property === "arguments" || property === "caller") return;
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) return;
Object.defineProperty(to, property, fromDescriptor);
};
var canCopyProperty = function(toDescriptor, fromDescriptor) {
return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
};
var changePrototype = (to, from) => {
const fromPrototype = Object.getPrototypeOf(from);
if (fromPrototype === Object.getPrototypeOf(to)) return;
Object.setPrototypeOf(to, fromPrototype);
};
var wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/\n${fromBody}`;
var toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
var toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
var changeToString = (to, from, name) => {
const withName = name === "" ? "" : `with ${name.trim()}() `;
const newToString = wrappedToString.bind(null, withName, from.toString());
Object.defineProperty(newToString, "name", toStringName);
Object.defineProperty(to, "toString", {
...toStringDescriptor,
value: newToString
});
};
function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
const { name } = to;
for (const property of Reflect.ownKeys(from)) copyProperty(to, from, property, ignoreNonConfigurable);
changePrototype(to, from);
changeToString(to, from, name);
return to;
}
// ../../node_modules/.pnpm/p-memoize@7.1.1/node_modules/p-memoize/dist/index.js
var cacheStore = /* @__PURE__ */ new WeakMap();
/**
[Memoize](https://en.wikipedia.org/wiki/Memoization) functions - An optimization used to speed up consecutive function calls by caching the result of calls with identical input.
@param fn - Function to be memoized.
@example
```
import {setTimeout as delay} from 'node:timer/promises';
import pMemoize from 'p-memoize';
import got from 'got';
const memoizedGot = pMemoize(got);
await memoizedGot('https://sindresorhus.com');
// This call is cached
await memoizedGot('https://sindresorhus.com');
await delay(2000);
// This call is not cached as the cache has expired
await memoizedGot('https://sindresorhus.com');
```
*/
function pMemoize(fn, { cacheKey = ([firstArgument]) => firstArgument, cache = /* @__PURE__ */ new Map() } = {}) {
const promiseCache = /* @__PURE__ */ new Map();
const memoized = function(...arguments_) {
const key = cacheKey(arguments_);
if (promiseCache.has(key)) return promiseCache.get(key);
const promise = (async () => {
try {
if (cache && await cache.has(key)) return await cache.get(key);
const result = await fn.apply(this, arguments_);
try {
return result;
} finally {
if (cache) await cache.set(key, result);
}
} finally {
promiseCache.delete(key);
}
})();
promiseCache.set(key, promise);
return promise;
};
mimicFunction(memoized, fn, { ignoreNonConfigurable: true });
cacheStore.set(memoized, cache);
return memoized;
}
// src/BinaryModule.ts
function inferGlueFlavor(binary) {
return binary.includes("harper_wasm_slim") ? "slim" : "full";
}
/**
* Resolve the glue flavor for a binary module.
*
* `glueFlavor` is intentionally optional on the public `BinaryModule` interface so
* older/custom BinaryModule-like objects remain structurally compatible. When it is
* absent, fall back to inferring the flavor from the binary URL.
*/
function resolveWasmGlueFlavor(binary) {
return binary.glueFlavor ?? inferGlueFlavor(typeof binary.url === "string" ? binary.url : binary.url.href);
}
function loadGlue(glueFlavor) {
if (glueFlavor === "slim") return harper_wasm_slim_exports;
return harper_wasm_exports;
}
function getDefaultGlueBinary(binary, glueFlavor) {
if (glueFlavor === "slim") return binary;
if (binary.includes("harper_wasm_bg.wasm")) return binary.replace("harper_wasm_bg.wasm", "harper_wasm_slim_bg.wasm");
return null;
}
function getInitInput(binary) {
if (typeof process !== "undefined" && binary.startsWith("file://")) return import(
/* webpackIgnore: true */
/* @vite-ignore */
"fs"
).then((fs) => new Promise((resolve, reject) => {
fs.readFile(new URL(binary).pathname, (err, data) => {
if (err) reject(err);
resolve(data);
});
}));
return binary;
}
async function loadBinaryUncached(binary, glueFlavor) {
const exports = loadGlue(glueFlavor);
const defaultGlueBinary = getDefaultGlueBinary(binary, glueFlavor);
if (defaultGlueBinary != null) try {
await __wbg_init$1({ module_or_path: getInitInput(defaultGlueBinary) });
} catch (err) {
if (glueFlavor === "slim") throw err;
}
await exports.default({ module_or_path: getInitInput(binary) });
return exports;
}
var loadBinaryByFlavor = {
full: pMemoize((binary) => loadBinaryUncached(binary, "full")),
slim: pMemoize((binary) => loadBinaryUncached(binary, "slim"))
};
function loadBinary(binary, glueFlavor) {
return loadBinaryByFlavor[glueFlavor](binary);
}
function createBinaryModuleFromUrl(url, glueFlavor) {
return BinaryModuleImpl.create(url, glueFlavor);
}
/** A wrapper around the underlying WebAssembly module that contains Harper's core code. Used to construct a `Linter`, as well as access some miscellaneous other functions. */
var BinaryModuleImpl = class {
url = "";
glueFlavor = "full";
inner = null;
/** Load a binary from a specified URL. This is the only recommended way to construct this type. */
static create(url, glueFlavor) {
const module = new SuperBinaryModule();
module.url = url;
module.glueFlavor = glueFlavor ?? inferGlueFlavor(typeof url === "string" ? url : url.href);
module.inner = PLazy.from(() => loadBinary(typeof module.url === "string" ? module.url : module.url.href, module.glueFlavor));
return module;
}
async getDefaultLintConfigAsJSON() {
return (await this.inner).get_default_lint_config_as_json();
}
async getDefaultLintConfig() {
return (await this.inner).get_default_lint_config();
}
async toTitleCase(text) {
return (await this.inner).to_title_case(text);
}
async setup() {
(await this.inner).setup();
}
};
var SuperBinaryModule = class extends BinaryModuleImpl {
async createLinter(dialect) {
return (await this.getBinaryModule()).Linter.new(dialect ?? Dialect$1.American);
}
async getBinaryModule() {
return await PLazy.from(() => loadBinary(typeof this.url === "string" ? this.url : this.url.href, this.glueFlavor));
}
};
export { BinaryModuleImpl, Dialect$1 as Dialect, Language$1 as Language, PLazy, SuggestionKind$1 as SuggestionKind, createBinaryModuleFromUrl, resolveWasmGlueFlavor };