Spaces:
Sleeping
Sleeping
File size: 2,748 Bytes
2434dca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ClassScope = void 0;
var _scopeflags = require("./scopeflags");
var _parseError = require("../parse-error");
class ClassScope {
constructor() {
this.privateNames = new Set();
this.loneAccessors = new Map();
this.undefinedPrivateNames = new Map();
}
}
exports.ClassScope = ClassScope;
class ClassScopeHandler {
constructor(parser) {
this.parser = void 0;
this.stack = [];
this.undefinedPrivateNames = new Map();
this.parser = parser;
}
current() {
return this.stack[this.stack.length - 1];
}
enter() {
this.stack.push(new ClassScope());
}
exit() {
const oldClassScope = this.stack.pop();
const current = this.current();
for (const [name, loc] of Array.from(oldClassScope.undefinedPrivateNames)) {
if (current) {
if (!current.undefinedPrivateNames.has(name)) {
current.undefinedPrivateNames.set(name, loc);
}
} else {
this.parser.raise(_parseError.Errors.InvalidPrivateFieldResolution, {
at: loc,
identifierName: name
});
}
}
}
declarePrivateName(name, elementType, loc) {
const {
privateNames,
loneAccessors,
undefinedPrivateNames
} = this.current();
let redefined = privateNames.has(name);
if (elementType & _scopeflags.ClassElementType.KIND_ACCESSOR) {
const accessor = redefined && loneAccessors.get(name);
if (accessor) {
const oldStatic = accessor & _scopeflags.ClassElementType.FLAG_STATIC;
const newStatic = elementType & _scopeflags.ClassElementType.FLAG_STATIC;
const oldKind = accessor & _scopeflags.ClassElementType.KIND_ACCESSOR;
const newKind = elementType & _scopeflags.ClassElementType.KIND_ACCESSOR;
redefined = oldKind === newKind || oldStatic !== newStatic;
if (!redefined) loneAccessors.delete(name);
} else if (!redefined) {
loneAccessors.set(name, elementType);
}
}
if (redefined) {
this.parser.raise(_parseError.Errors.PrivateNameRedeclaration, {
at: loc,
identifierName: name
});
}
privateNames.add(name);
undefinedPrivateNames.delete(name);
}
usePrivateName(name, loc) {
let classScope;
for (classScope of this.stack) {
if (classScope.privateNames.has(name)) return;
}
if (classScope) {
classScope.undefinedPrivateNames.set(name, loc);
} else {
this.parser.raise(_parseError.Errors.InvalidPrivateFieldResolution, {
at: loc,
identifierName: name
});
}
}
}
exports.default = ClassScopeHandler;
//# sourceMappingURL=class-scope.js.map
|