Skip to content

Commit 93b4a66

Browse files
committed
fix deletion bug maybe?
1 parent 2f4e9f2 commit 93b4a66

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingap/steve",
3-
"version": "2.0.7",
3+
"version": "2.0.8",
44
"exports": "./index.ts",
55
"description": "STEVE is a configurable template engine that allows JavaScript to run in files to create files. It has a plugin system to allow for custom generation and a built-in site generator.",
66
"tasks": {

src/core/steve.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,18 @@ class STEVE {
232232
}
233233
} else if (_current.includes(this.tags.end)) {
234234
if (_checkForCode) {
235-
const _fragment = eval(
236-
`(() => {const ${this.globalName} = ${
237-
objectStringify(this.#createGlobalObject(_data))
238-
}; ${_current.slice(0, -this.tags.end.length)}})()`,
239-
);
240-
if (_fragment != null) {
241-
_result += _fragment;
235+
try {
236+
const _fragment = eval(
237+
`(() => {const ${this.globalName} = ${
238+
objectStringify(this.#createGlobalObject(_data))
239+
}; ${_current.slice(0, -this.tags.end.length)}})()`,
240+
);
241+
242+
if (_fragment != null) {
243+
_result += _fragment;
244+
}
245+
} catch (err) {
246+
throw new Error(`${err} inside STEVE tags: ${_current.slice(0, -this.tags.end.length)}`)
242247
}
243248

244249
_current = '';

test/steve.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ Deno.test('STEVE: unmatched start tag throws error', () => {
155155
assertThrows(
156156
() => STEVE.render(content, data),
157157
Error,
158-
'unmatched start STEVE tag found!',
159158
);
160159
});
161160

@@ -166,7 +165,6 @@ Deno.test('STEVE: unmatched end tag throws error', () => {
166165
assertThrows(
167166
() => STEVE.render(content, data),
168167
Error,
169-
'unmatched end STEVE tag found!',
170168
);
171169
});
172170

@@ -177,6 +175,15 @@ Deno.test('STEVE: nested STEVE tags throw error', () => {
177175
assertThrows(
178176
() => STEVE.render(content, data),
179177
Error,
180-
'nested STEVE tags are not allowed!',
181178
);
182179
});
180+
181+
Deno.test('STEVE: error in STEVE tags is caught correctly', () => {
182+
const content = 'Hello, <steve> funcion error </steve>';
183+
const data = {};
184+
185+
assertThrows(
186+
() => STEVE.render(content, data),
187+
TypeError,
188+
);
189+
})

0 commit comments

Comments
 (0)