Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 60 additions & 12 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29290,6 +29290,23 @@ static __exception JSAtom js_parse_from_clause(JSParseState *s)
return module_name;
}

static bool has_unmatched_surrogate(const uint16_t *s, size_t n)
{
size_t i;

for (i = 0; i < n; i++) {
if (is_lo_surrogate(s[i]))
return true;
if (!is_hi_surrogate(s[i]))
continue;
if (++i == n)
return true;
if (!is_lo_surrogate(s[i]))
return true;
}
return false;
}

static __exception int js_parse_export(JSParseState *s)
{
JSContext *ctx = s->ctx;
Expand Down Expand Up @@ -29323,22 +29340,39 @@ static __exception int js_parse_export(JSParseState *s)
case '{':
first_export = m->export_entries_count;
while (s->token.val != '}') {
if (!token_is_ident(s->token.val)) {
js_parse_error(s, "identifier expected");
if (token_is_ident(s->token.val)) {
local_name = JS_DupAtom(ctx, s->token.u.ident.atom);
} else if (s->token.val == TOK_STRING) {
local_name = JS_ValueToAtom(ctx, s->token.u.str.str);
if (local_name == JS_ATOM_NULL) {
return -1;
}
} else {
js_parse_error(s, "identifier or string expected");
return -1;
}
local_name = JS_DupAtom(ctx, s->token.u.ident.atom);
export_name = JS_ATOM_NULL;
if (next_token(s))
goto fail;
if (token_is_pseudo_keyword(s, JS_ATOM_as)) {
if (next_token(s))
goto fail;
if (!token_is_ident(s->token.val)) {
js_parse_error(s, "identifier expected");
if (token_is_ident(s->token.val)) {
export_name = JS_DupAtom(ctx, s->token.u.ident.atom);
} else if (s->token.val == TOK_STRING) {
JSString *p = JS_VALUE_GET_STRING(s->token.u.str.str);
if (p->is_wide_char && has_unmatched_surrogate(str16(p), p->len)) {
js_parse_error(s, "illegal export name");
return -1;
}
export_name = JS_ValueToAtom(ctx, s->token.u.str.str);
if (export_name == JS_ATOM_NULL) {
return -1;
}
} else {
js_parse_error(s, "identifier or string expected");
goto fail;
}
export_name = JS_DupAtom(ctx, s->token.u.ident.atom);
if (next_token(s)) {
fail:
JS_FreeAtom(ctx, local_name);
Expand Down Expand Up @@ -29382,11 +29416,19 @@ static __exception int js_parse_export(JSParseState *s)
/* export ns from */
if (next_token(s))
return -1;
if (!token_is_ident(s->token.val)) {
js_parse_error(s, "identifier expected");

if (token_is_ident(s->token.val)) {
export_name = JS_DupAtom(ctx, s->token.u.ident.atom);
} else if (s->token.val == TOK_STRING) {
export_name = JS_ValueToAtom(ctx, s->token.u.str.str);
if (export_name == JS_ATOM_NULL) {
return -1;
}
} else {
js_parse_error(s, "identifier or string expected");
return -1;
}
export_name = JS_DupAtom(ctx, s->token.u.ident.atom);

if (next_token(s))
goto fail1;
module_name = js_parse_from_clause(s);
Expand Down Expand Up @@ -29560,11 +29602,17 @@ static __exception int js_parse_import(JSParseState *s)
return -1;

while (s->token.val != '}') {
if (!token_is_ident(s->token.val)) {
js_parse_error(s, "identifier expected");
if (token_is_ident(s->token.val)) {
import_name = JS_DupAtom(ctx, s->token.u.ident.atom);
} else if (s->token.val == TOK_STRING) {
import_name = JS_ValueToAtom(ctx, s->token.u.str.str);
if (import_name == JS_ATOM_NULL) {
return -1;
}
} else {
js_parse_error(s, "identifier or string expected expected");
return -1;
}
import_name = JS_DupAtom(ctx, s->token.u.ident.atom);
local_name = JS_ATOM_NULL;
if (next_token(s))
goto fail;
Expand Down
2 changes: 1 addition & 1 deletion test262.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ __proto__
__setter__
AggregateError
align-detached-buffer-semantics-with-web-reality
arbitrary-module-namespace-names=skip
arbitrary-module-namespace-names
array-find-from-last
array-grouping
Array.fromAsync
Expand Down
1 change: 1 addition & 0 deletions test262_errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test262/test/language/expressions/in/private-field-invalid-assignment-target.js:
test262/test/language/expressions/in/private-field-invalid-assignment-target.js:23: strict mode: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js:31: Test262Error: Expected SameValue(«"bad"», «"ok"») to be true
test262/test/language/expressions/object/computed-property-name-topropertykey-before-value-evaluation.js:31: strict mode: Test262Error: Expected SameValue(«"bad"», «"ok"») to be true
test262/test/language/module-code/export-expname-string-binding.js:19: unexpected error type: Test262: This statement should not be evaluated.
test262/test/language/module-code/top-level-await/module-graphs-does-not-hang.js:10: TypeError: $DONE() not called
test262/test/language/statements/class/elements/syntax/valid/grammar-field-named-get-followed-by-generator-asi.js:40: SyntaxError: invalid property name
test262/test/language/statements/class/elements/syntax/valid/grammar-field-named-get-followed-by-generator-asi.js:40: strict mode: SyntaxError: invalid property name
Expand Down
12 changes: 12 additions & 0 deletions tests/fixture_string_exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// ES2020 string export names test fixture
export const regularExport = "regular";
const value1 = "value-1";
const value2 = "value-2";

// String export names (ES2020)
export { value1 as "string-export-1" };
export { value2 as "string-export-2" };

// Mixed: regular and string exports
const mixed = "mixed-value";
export { mixed as normalName, mixed as "string-name" };
25 changes: 25 additions & 0 deletions tests/test_string_exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Test ES2020 string export/import names
import { assert } from "./assert.js";
import * as mod from "./fixture_string_exports.js";

// Test string import names
import { "string-export-1" as str1 } from "./fixture_string_exports.js";
import { "string-export-2" as str2 } from "./fixture_string_exports.js";
import { "string-name" as strMixed } from "./fixture_string_exports.js";

// Test regular imports still work
import { regularExport, normalName } from "./fixture_string_exports.js";

// Verify values
assert(str1 === "value-1");
assert(str2 === "value-2");
assert(strMixed === "mixed-value");
assert(regularExport === "regular");
assert(normalName === "mixed-value");

// Verify module namespace has string-named exports
assert(mod["string-export-1"] === "value-1");
assert(mod["string-export-2"] === "value-2");
assert(mod["string-name"] === "mixed-value");
assert(mod.regularExport === "regular");
assert(mod.normalName === "mixed-value");