Files
smart-city-digital-twin-mar…/smart-app-city/frontend/node_modules/metro-transform-plugins/src/inline-plugin.js.flow
Eric FELIXINE e30ae8ed09 feat(smart-app): implement complete mobile app MVP
- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
2026-06-01 18:00:35 -04:00

184 lines
5.0 KiB
Plaintext

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall react_native
*/
'use strict';
import type {PluginObj} from '@babel/core';
import type {Binding, NodePath, Scope} from '@babel/traverse';
import type {
CallExpression,
MemberExpression,
Node,
ObjectExpression,
} from '@babel/types';
// type only import. No runtime dependency
// eslint-disable-next-line import/no-extraneous-dependencies
import typeof * as Types from '@babel/types';
const createInlinePlatformChecks = require('./utils/createInlinePlatformChecks');
export type Options = {
dev: boolean,
inlinePlatform: boolean,
isWrapped: boolean,
requireName?: string,
platform: string,
};
type State = {opts: Options};
const env = {name: 'env'};
const nodeEnv = {name: 'NODE_ENV'};
const processId = {name: 'process'};
const dev = {name: '__DEV__'};
function inlinePlugin(
{types: t}: {types: Types},
options: Options,
): PluginObj<State> {
const {
isAssignmentExpression,
isIdentifier,
isMemberExpression,
isObjectExpression,
isObjectMethod,
isObjectProperty,
isSpreadElement,
isStringLiteral,
} = t;
const {isPlatformNode, isPlatformSelectNode} = createInlinePlatformChecks(
t,
options.requireName || 'require',
);
// $FlowFixMe[deprecated-type]
function isGlobal(binding: ?Binding): boolean %checks {
return !binding;
}
const isFlowDeclared = (binding: Binding) =>
t.isDeclareVariable(binding.path);
// $FlowFixMe[deprecated-type]
function isGlobalOrFlowDeclared(binding: ?Binding): boolean %checks {
return isGlobal(binding) || isFlowDeclared(binding);
}
const isLeftHandSideOfAssignmentExpression = (
node: Node,
parent: Node,
): boolean => isAssignmentExpression(parent) && parent.left === node;
const isProcessEnvNodeEnv = (node: MemberExpression, scope: Scope): boolean =>
isIdentifier(node.property, nodeEnv) &&
isMemberExpression(node.object) &&
isIdentifier(node.object.property, env) &&
isIdentifier(node.object.object, processId) &&
isGlobal(scope.getBinding(processId.name));
const isDev = (node: Node, parent: Node, scope: Scope): boolean =>
isIdentifier(node, dev) &&
isGlobalOrFlowDeclared(scope.getBinding(dev.name));
function findProperty(
objectExpression: ObjectExpression,
key: string,
fallback: () => Node,
): Node {
let value = null;
for (const p of objectExpression.properties) {
if (!isObjectProperty(p) && !isObjectMethod(p)) {
continue;
}
if (
(isIdentifier(p.key) && p.key.name === key) ||
(isStringLiteral(p.key) && p.key.value === key)
) {
if (isObjectProperty(p)) {
value = p.value;
break;
} else if (isObjectMethod(p)) {
value = t.toExpression(p);
break;
}
}
}
return value ?? fallback();
}
function hasStaticProperties(objectExpression: ObjectExpression): boolean {
return objectExpression.properties.every(p => {
if (p.computed || isSpreadElement(p)) {
return false;
}
if (isObjectMethod(p) && p.kind !== 'method') {
return false;
}
return isIdentifier(p.key) || isStringLiteral(p.key);
});
}
return {
visitor: {
ReferencedIdentifier(path: NodePath<Node>, state: State): void {
if (!state.opts.dev && isDev(path.node, path.parent, path.scope)) {
path.replaceWith(t.booleanLiteral(state.opts.dev));
}
},
MemberExpression(path: NodePath<MemberExpression>, state: State): void {
const node = path.node;
const scope = path.scope;
const opts = state.opts;
if (!isLeftHandSideOfAssignmentExpression(node, path.parent)) {
if (
opts.inlinePlatform &&
isPlatformNode(node, scope, !!opts.isWrapped)
) {
path.replaceWith(t.stringLiteral(opts.platform));
} else if (!opts.dev && isProcessEnvNodeEnv(node, scope)) {
path.replaceWith(
t.stringLiteral(opts.dev ? 'development' : 'production'),
);
}
}
},
CallExpression(path: NodePath<CallExpression>, state: State): void {
const node = path.node;
const scope = path.scope;
const arg = node.arguments[0];
const opts = state.opts;
if (
opts.inlinePlatform &&
isPlatformSelectNode(node, scope, !!opts.isWrapped) &&
isObjectExpression(arg)
) {
if (hasStaticProperties(arg)) {
const fallback = () =>
findProperty(arg, 'native', () =>
findProperty(arg, 'default', () => t.identifier('undefined')),
);
path.replaceWith(findProperty(arg, opts.platform, fallback));
}
}
},
},
};
}
module.exports = inlinePlugin;