@@ -16,11 +16,21 @@ const DynamicExports = require("./DynamicExports");
1616const HarmonyExports = require ( "./HarmonyExports" ) ;
1717const ModuleDecoratorDependency = require ( "./ModuleDecoratorDependency" ) ;
1818
19+ /** @typedef {import("estree").Super } Super */
20+ /** @typedef {import("estree").CallExpression } CallExpression */
1921/** @typedef {import("estree").Expression } ExpressionNode */
22+ /** @typedef {import("estree").Expression } Expression */
23+ /** @typedef {import("estree").AssignmentExpression } AssignmentExpression */
24+
2025/** @typedef {import("../NormalModule") } NormalModule */
2126/** @typedef {import("../javascript/BasicEvaluatedExpression") } BasicEvaluatedExpression */
2227/** @typedef {import("../javascript/JavascriptParser") } JavascriptParser */
28+ /** @typedef {import("./CommonJsDependencyHelpers").CommonJSDependencyBaseKeywords } CommonJSDependencyBaseKeywords */
2329
30+ /**
31+ * @param {TODO } expr expression
32+ * @returns {Expression } returns the value of property descriptor
33+ */
2434const getValueOfPropertyDescription = expr => {
2535 if ( expr . type !== "ObjectExpression" ) return ;
2636 for ( const property of expr . properties ) {
@@ -31,6 +41,15 @@ const getValueOfPropertyDescription = expr => {
3141 }
3242} ;
3343
44+ /**
45+ * The purpose of this function is to check whether an expression is a truthy literal or not. This is
46+ * useful when parsing CommonJS exports, because CommonJS modules can export any value, including falsy
47+ * values like `null` and `false`. However, exports should only be created if the exported value is truthy.
48+ *
49+ * @param {Expression } expr expression being checked
50+ * @returns {boolean } true, when the expression is a truthy literal
51+ *
52+ */
3453const isTruthyLiteral = expr => {
3554 switch ( expr . type ) {
3655 case "Literal" :
@@ -41,6 +60,14 @@ const isTruthyLiteral = expr => {
4160 return false ;
4261} ;
4362
63+ /**
64+ * The purpose of this function is to check whether an expression is a falsy literal or not. This is
65+ * useful when parsing CommonJS exports, because CommonJS modules can export any value, including falsy
66+ * values like `null` and `false`. However, exports should only be created if the exported value is truthy.
67+ *
68+ * @param {Expression } expr expression being checked
69+ * @returns {boolean } true, when the expression is a falsy literal
70+ */
4471const isFalsyLiteral = expr => {
4572 switch ( expr . type ) {
4673 case "Literal" :
@@ -97,6 +124,13 @@ class CommonJsExportsParserPlugin {
97124 const enableStructuredExports = ( ) => {
98125 DynamicExports . enable ( parser . state ) ;
99126 } ;
127+
128+ /**
129+ * @param {boolean } topLevel true, when the export is on top level
130+ * @param {string[] } members members of the export
131+ * @param {Expression } valueExpr expression for the value
132+ * @returns {void }
133+ */
100134 const checkNamespace = ( topLevel , members , valueExpr ) => {
101135 if ( ! DynamicExports . isEnabled ( parser . state ) ) return ;
102136 if ( members . length > 0 && members [ 0 ] === "__esModule" ) {
@@ -126,6 +160,13 @@ class CommonJsExportsParserPlugin {
126160 . tap ( "CommonJsPlugin" , evaluateToString ( "object" ) ) ;
127161
128162 // exporting //
163+
164+ /**
165+ * @param {AssignmentExpression } expr expression
166+ * @param {CommonJSDependencyBaseKeywords } base commonjs base keywords
167+ * @param {string[] } members members of the export
168+ * @returns {boolean } true, when the expression was handled
169+ */
129170 const handleAssignExport = ( expr , base , members ) => {
130171 if ( HarmonyExports . isEnabled ( parser . state ) ) return ;
131172 // Handle reexporting
@@ -233,6 +274,14 @@ class CommonJsExportsParserPlugin {
233274 } ) ;
234275
235276 // Self reference //
277+
278+ /**
279+ * @param { Expression | Super } expr expression
280+ * @param {CommonJSDependencyBaseKeywords } base commonjs base keywords
281+ * @param {string[] } members members of the export
282+ * @param {CallExpression } call call expression
283+ * @returns {boolean } true, when the expression was handled
284+ */
236285 const handleAccessExport = ( expr , base , members , call = undefined ) => {
237286 if ( HarmonyExports . isEnabled ( parser . state ) ) return ;
238287 if ( members . length === 0 ) {
0 commit comments