/*
 * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var path=require("path");const RULENAME="oj-ts-poly-promise";const SHORT="The 'promise' polyfill should not be declared explicitly in define/require()";const DESCRIPTION="The Promise polyfill is no longer distributed with JET v11 and higher. Support for Internet Explorer 11 and ES5 "+"has been removed starting with JET v11.  All modern browsers provide direct support for Promise and the Promise "+"polyfill should no longer be referenced separately.";const DEFINE="define";const REQUIRE="require";var nt;class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT}register(regCtx){nt=regCtx.tsNodeTypes;return{CallExpression:this._onCall}}_onCall(ruleCtx,node){var args,arg,argVal,i,start,issue;if(node.callee&&(node.callee.name===DEFINE||node.callee.name===REQUIRE)){if(node.arguments&&node.arguments.length>=1){if(node.arguments[0].type===nt.ARRAY_EXPR){args=node.arguments[0].elements;for(i=0;i<args.length;i++){arg=args[i];if(arg&&arg.type==="Literal"){argVal=arg.raw;argVal=path.basename(argVal).toLowerCase();if(argVal.includes("promise")){start=arg.range[0];start=start+arg.raw.toLowerCase().indexOf("promise");issue=new ruleCtx.Issue(node.callee.name+"() explicitly loads polyfill 'promise'");issue.setPosition(null,null,start,start+6);ruleCtx.reporter.addIssue(issue,ruleCtx);break}}}}}}}}module.exports=Rule;